【发布时间】:2012-08-07 16:32:32
【问题描述】:
Pivotal Tracker 是我使用的一个项目管理工具。我正在使用 Pivotal Tracker Ruby Gem 来访问 API。
我正在尝试使用他们分配给他们的点数创建每个成员的哈希值。
最终结果应该类似于:
{"Joe Jones"=>5, "Jane Smith"=>6, "John Doe"=>3}
我已经在@members 中创建了项目中每个成员的数组。
我编写了下面的代码来帮助我创建每个成员的哈希值以及他/她分配的相应数量的故事,但我真正需要的是分配给他们的每个故事的 estimate 值的总和(估计是给定故事的点值)。
#creates a hash of members to number of stories assigned.
for i in 0..@members.length-1
my_hash[@members[i]] = project.stories.all(:owned_by => @members[i], :current_state => ['started', 'unstarted']).length
end
所以,我想知道,对于每个成员,我如何总结每个故事 owned_by 那个特定成员的 estimate 值。 注意:未估计的故事在估计字段中为 -1,不应包含在总和中。
任何有关如何修改上述循环以遍历每个故事并对估计值求和(不包括负 1s)的帮助将不胜感激。我觉得有一些不错的 Ruby jujitsu 可以完成这项工作!
project.stories.all(:owned_by => @members[i], :current_state => ['started', 'unstarted']) 返回的示例数据以防人们对格式感到疑惑:
[#<PivotalTracker::Story:0x007f9d6b8 @id=314, @url="http://www.pivotaltracker.com/", @created_at=#<DateTime: 2012-06-18T20:23:42+00:00 ((2456097j,73422s,0n),+0s,2299161j)>, @accepted_at=nil, @project_id=12345, @name="Test ", @description="This is the description for \"Test\"", @story_type="feature", @estimate=5, @current_state="unstarted", @requested_by="joe jones", @owned_by="joe jones", @labels=nil, @jira_id=nil, @jira_url=nil, @other_id=nil, @integration_id=nil, @deadline=nil, @attachments=[]>, #<PivotalTracker::Story:0x007f9d6b8 @id=315, @url="http://www.pivotaltracker.com/", @created_at=#<DateTime: 2012-06-18T20:25:20+00:00 ((2456097j,73520s,0n),+0s,2299161j)>, @accepted_at=nil, @project_id=12345, @name="Test 2", @description="This is the description for \"Test 2\"", @story_type="feature", @estimate=3, @current_state="unstarted", @requested_by="joe jones", @owned_by="joe jones"", @labels=nil, @jira_id=nil, @jira_url=nil, @other_id=nil, @integration_id=nil, @deadline=nil, @attachments=[]>, #<PivotalTracker::Story:0x007f9d6b8 @id=316, @url="http://www.pivotaltracker.com/story/", @created_at=#<DateTime: 2012-06-18T20:25:26+00:00 ((2456097j,73526s,0n),+0s,2299161j)>, @accepted_at=nil, @project_id=12345, @name="Test 3", @description="Description for Test 3 ", @story_type="feature", @estimate=-1, @current_state="started", @requested_by="joe jones", @owned_by="joe jones", @labels=nil, @jira_id=nil, @jira_url=nil, @other_id=nil, @integration_id=nil, @deadline=nil, @attachments=[]>]
附:关于如何使这个标题更具描述性的建议将不胜感激。
【问题讨论】:
标签: ruby arrays hashmap hash-of-hashes pivotaltracker