Class: Dev::TargetProcess::UserStory

Inherits:
Object
  • Object
show all
Defined in:
lib/firespring_dev_commands/target_process/user_story.rb

Overview

Class containing user story information

Constant Summary collapse

RESOURCE_TYPE =

The resource type for the api endpoint

'UserStory'.freeze
PATH =

The api path for user story requests

'/UserStories'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ UserStory

Returns a new instance of UserStory.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 14

def initialize(data)
  @data = data
  @id = data['Id']
  @type = data['ResourceType']
  @name = data['Name']
  @description = data['Description']
  @state = data['EntityState']['Name'] if data['EntityState']
  @project = Project.new(data['Project']) if data['Project']
  @owner = User.new(data['Owner']) if data['Owner']
  @creator = User.new(data['Creator']) if data['Creator']
  @release = Release.new(data['Release']) if data['Release']
  @team = Team.new(data['Team']) if data['Team']
  @start_date = parse_time(data['StartDate'])
  @end_date = parse_time(data['EndDate'])
  @create_date = parse_time(data['CreateDate'])
  @modify_date = parse_time(data['ModifyDate'])
  @tags = data['Tags']
  @effort = data['Effort']
  @time_spent = data['TimeSpent']
  @last_state_change_date = parse_time(data['LastStateChangeDate'])
end

Instance Attribute Details

#create_dateObject

Returns the value of attribute create_date.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def create_date
  @create_date
end

#creatorObject

Returns the value of attribute creator.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def creator
  @creator
end

#dataObject

Returns the value of attribute data.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def data
  @data
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def description
  @description
end

#effortObject

Returns the value of attribute effort.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def effort
  @effort
end

#end_dateObject

Returns the value of attribute end_date.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def end_date
  @end_date
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def id
  @id
end

#last_state_change_dateObject

Returns the value of attribute last_state_change_date.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def last_state_change_date
  @last_state_change_date
end

#modify_dateObject

Returns the value of attribute modify_date.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def modify_date
  @modify_date
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def name
  @name
end

#ownerObject

Returns the value of attribute owner.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def owner
  @owner
end

#priorityObject

Returns the value of attribute priority.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def priority
  @priority
end

#projectObject

Returns the value of attribute project.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def project
  @project
end

#releaseObject

Returns the value of attribute release.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def release
  @release
end

#start_dateObject

Returns the value of attribute start_date.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def start_date
  @start_date
end

#stateObject

Returns the value of attribute state.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def state
  @state
end

#tagsObject

Returns the value of attribute tags.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def tags
  @tags
end

#teamObject

Returns the value of attribute team.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def team
  @team
end

#time_spentObject

Returns the value of attribute time_spent.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def time_spent
  @time_spent
end

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 11

def type
  @type
end

Instance Method Details

#cycle_timeObject

Calculate the cycle time as the amount of time the story was open



44
45
46
47
48
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 44

def cycle_time
  return 1.0 unless start_date && end_date

  (end_date - start_date).to_f / (60 * 60 * 24)
end

#parse_time(string) ⇒ Object

Parse the dot net time representation into something that ruby can use



37
38
39
40
41
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 37

def parse_time(string)
  return nil unless string && !string.empty?

  ::Time.at(string.slice(6, 10).to_i)
end

#team_cycle_time(team_ids) ⇒ Object

Returns the time the team was responsible for the issue was



51
52
53
54
55
56
57
58
59
# File 'lib/firespring_dev_commands/target_process/user_story.rb', line 51

def team_cycle_time(team_ids)
  # Calculate the difference and convert to days
  finished_dev_query = Dev::TargetProcess::Query.new
  finished_dev_query.filter_by_team_ids(team_ids)
  finished_dev_query.filter_by_entity_type(Dev::TargetProcess::UserStory::RESOURCE_TYPE)
  finished_dev_query.filter_by_entity_id(id)
  team_assignments = Dev::TargetProcess.new.team_assignments(finished_dev_query)
  team_assignments.sum(&:cycle_time)
end