class Torque::Story

Stores the data to represent a Pivotal Tracker story

Attributes

current_state[RW]

The current state of the story (finished, accepted, etc)

date_accepted[RW]

The date that the story was accepted, or nil if it has not been accepted yet

description[RW]

The story description

estimate[RW]

The estimate for the story

id[RW]

The story's ID

labels[RW]

The labels for the story

name[RW]

The name of the story

owner[RW]

The owner of the story

project_id[RW]

The ID of the story's project

type[RW]

The story's type (feature, chore, etc)

Public Class Methods

create(html_hash) click to toggle source

@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
new(html_hash) click to toggle source

@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
sort_list(stories) click to toggle source

@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

parse() click to toggle source

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
url() click to toggle source

@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

handle_nil(default, value) click to toggle source

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