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
所以,我想知道,对于每个成员,我如何总结该特定成员estimate
的每个故事的价值。注意:未估计的故事在估计字段中有-1,不应包含在总和中。owned_by
关于如何修改上述循环以遍历每个故事并对估计值求和(不包括负 1s)的任何帮助将不胜感激。我觉得有一些不错的 Ruby 柔术可以完成这件事!
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=[]>]
PS 关于如何使这个标题更具描述性的建议将不胜感激。