Class: Torque::Story

Inherits:
Object
  • Object
show all
Defined in:
lib/torque/story.rb

Overview

Stores the data to represent a Pivotal Tracker story

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html_hash) ⇒ Story

Creates a new story without parsing its fields

Parameters:

  • html_hash

    A hash (of html elements keyed by their tags) generated from Pivotal Tracker story html



59
60
61
# File 'lib/torque/story.rb', line 59

def initialize(html_hash)
  @html_hash = html_hash
end

Instance Attribute Details

#current_stateObject

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_acceptedObject

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

#descriptionObject

The story description



17
18
19
# File 'lib/torque/story.rb', line 17

def description
  @description
end

#estimateObject

The estimate for the story



21
22
23
# File 'lib/torque/story.rb', line 21

def estimate
  @estimate
end

#idObject

The story’s ID



25
26
27
# File 'lib/torque/story.rb', line 25

def id
  @id
end

#labelsObject

The labels for the story



29
30
31
# File 'lib/torque/story.rb', line 29

def labels
  @labels
end

#nameObject

The name of the story



33
34
35
# File 'lib/torque/story.rb', line 33

def name
  @name
end

#ownerObject

The owner of the story



37
38
39
# File 'lib/torque/story.rb', line 37

def owner
  @owner
end

#project_idObject

The ID of the story’s project



41
42
43
# File 'lib/torque/story.rb', line 41

def project_id
  @project_id
end

#typeObject

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.

Parameters:

  • html_hash

    A hash (of html elements keyed by their tags) generated from Pivotal Tracker story html

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.

Parameters:

  • stories

    A list of stories

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

#parseObject

Parses the story’s fields from its html hash

Returns:

  • The story (self)



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

#urlObject

Returns The url pointing to the story.

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