class Torque::Story
Stores the data to represent a Pivotal
Tracker story
Attributes
The current state of the story (finished, accepted, etc)
The date that the story was accepted, or nil if it has not been accepted yet
The story description
The estimate for the story
The story's ID
The labels for the story
The name of the story
The owner of the story
The ID of the story's project
The story's type (feature, chore, etc)
Public Class Methods
@param html_hash A hash (of html elements keyed by their tags) generated from Pivotal
Tracker story html
@return A new story whose fields were parsed from the html_hash provided
# File lib/torque/story.rb, line 51 def self.create(html_hash) Story.new(html_hash).parse end
@param html_hash A hash (of html elements keyed by their tags) generated from Pivotal
Tracker story html
Creates a new story without parsing its fields
# File lib/torque/story.rb, line 59 def initialize(html_hash) @html_hash = html_hash end
@param stories A list of stories @return The list of stories sorted from most to least recently accepted
# 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
Public Instance Methods
Parses the story's fields from its html hash
@return The story (self)
# 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
@return The url pointing to the story
# File lib/torque/story.rb, line 72 def url "https://www.pivotaltracker.com/story/show/#{id}" end
Private Instance Methods
If the second input is an empty array, returns the first input Else returns the index 0 of the second
# File lib/torque/story.rb, line 65 def handle_nil(default, value) (value.nil? ? default : value) end