Class: Torque::Story
- Inherits:
-
Object
- Object
- Torque::Story
- Defined in:
- lib/torque/story.rb
Overview
Stores the data to represent a Pivotal Tracker story
Instance Attribute Summary collapse
-
#current_state ⇒ Object
The current state of the story (finished, accepted, etc).
-
#date_accepted ⇒ Object
The date that the story was accepted, or nil if it has not been accepted yet.
-
#description ⇒ Object
The story description.
-
#estimate ⇒ Object
The estimate for the story.
-
#id ⇒ Object
The story’s ID.
-
#labels ⇒ Object
The labels for the story.
-
#name ⇒ Object
The name of the story.
-
#owner ⇒ Object
The owner of the story.
-
#project_id ⇒ Object
The ID of the story’s project.
-
#type ⇒ Object
The story’s type (feature, chore, etc).
Class Method Summary collapse
-
.create(html_hash) ⇒ Object
A new story whose fields were parsed from the html_hash provided.
-
.sort_list(stories) ⇒ Object
The list of stories sorted from most to least recently accepted.
Instance Method Summary collapse
-
#initialize(html_hash) ⇒ Story
constructor
Creates a new story without parsing its fields.
-
#parse ⇒ Object
Parses the story’s fields from its html hash.
-
#url ⇒ Object
The url pointing to the story.
Constructor Details
#initialize(html_hash) ⇒ Story
Creates a new story without parsing its fields
59 60 61 |
# File 'lib/torque/story.rb', line 59 def initialize(html_hash) @html_hash = html_hash end |
Instance Attribute Details
#current_state ⇒ Object
The current state of the story (finished, accepted, etc)
9 10 11 |
# File 'lib/torque/story.rb', line 9 def current_state @current_state end |
#date_accepted ⇒ Object
The date that the story was accepted, or nil if it has not been accepted yet
13 14 15 |
# File 'lib/torque/story.rb', line 13 def date_accepted @date_accepted end |
#description ⇒ Object
The story description
17 18 19 |
# File 'lib/torque/story.rb', line 17 def description @description end |
#estimate ⇒ Object
The estimate for the story
21 22 23 |
# File 'lib/torque/story.rb', line 21 def estimate @estimate end |
#id ⇒ Object
The story’s ID
25 26 27 |
# File 'lib/torque/story.rb', line 25 def id @id end |
#labels ⇒ Object
The labels for the story
29 30 31 |
# File 'lib/torque/story.rb', line 29 def labels @labels end |
#name ⇒ Object
The name of the story
33 34 35 |
# File 'lib/torque/story.rb', line 33 def name @name end |
#owner ⇒ Object
The owner of the story
37 38 39 |
# File 'lib/torque/story.rb', line 37 def owner @owner end |
#project_id ⇒ Object
The ID of the story’s project
41 42 43 |
# File 'lib/torque/story.rb', line 41 def project_id @project_id end |
#type ⇒ Object
The story’s type (feature, chore, etc)
45 46 47 |
# File 'lib/torque/story.rb', line 45 def type @type end |
Class Method Details
.create(html_hash) ⇒ Object
Returns A new story whose fields were parsed from the html_hash provided.
51 52 53 |
# File 'lib/torque/story.rb', line 51 def self.create(html_hash) Story.new(html_hash).parse end |
.sort_list(stories) ⇒ Object
Returns The list of stories sorted from most to least recently accepted.
124 125 126 127 |
# File 'lib/torque/story.rb', line 124 def self.sort_list(stories) sorted = stories.sort { |s1, s2| -(s1.date_accepted <=> s2.date_accepted) } sorted end |
Instance Method Details
#parse ⇒ Object
Parses the story’s fields from its html hash
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/torque/story.rb', line 80 def parse html_hash = @html_hash # Default values @current_state = "" @date_accepted = nil # [Date] @description = "" @estimate = -1 @id = -1 @labels = "" # [Array] @name = "" @owner = "" @project_id = -1 @type = "" # Processes each field @current_state = handle_nil(@current_state, html_hash["current_state"]) @description = handle_nil(@description, html_hash["description"]) @name = handle_nil(@name, html_hash["name"]) @owner = handle_nil(@owner, html_hash["owned_by"]) @type = handle_nil(@type, html_hash["story_type"]) @estimate = Integer(handle_nil(@estimate, html_hash["estimate"])) @project_id = Integer(handle_nil(@project_id, html_hash["project_id"])) @id = Integer(handle_nil(@id, html_hash["id"])) @labels = handle_nil(@labels, html_hash["labels"]) @labels = @labels.split(",") date_acceptedString = html_hash["accepted_at"] if(date_acceptedString != nil && date_acceptedString != "") @date_accepted = Date.strptime(date_acceptedString, "%Y/%m/%d") end # Returns the parsed story self end |
#url ⇒ Object
Returns The url pointing to the story.
72 73 74 |
# File 'lib/torque/story.rb', line 72 def url "https://www.pivotaltracker.com/story/show/#{id}" end |