Class: Pivotalprinter::Story

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

Constant Summary collapse

FIELDS =
[ :name, :id, :story_type, :estimate, :current_state, :description, :requested_by, :labels, :created_at, :updated_at ]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Story

Returns a new instance of Story.



8
9
10
11
12
13
14
15
# File 'lib/pivotalprinter/story.rb', line 8

def initialize(xml)
  FIELDS.each do |field|
    value = xml.css("#{field}")
    send "#{field}=", value.first.full? { |v| v.send(:text) } || value.send(:text)
  end
  created_at and self.created_at = Time.parse(created_at)
  updated_at and self.updated_at = Time.parse(updated_at)
end

Class Method Details

.open(ids) ⇒ Object



17
18
19
20
21
22
# File 'lib/pivotalprinter/story.rb', line 17

def self.open(ids)
  ids.map do |id|
    response = Client.get "/projects/#{Client.project}/stories/#{id}"
    self.new(response.css('story'))
  end
end

Instance Method Details

#pointsObject



24
25
26
# File 'lib/pivotalprinter/story.rb', line 24

def points
  estimate.to_i >= 0 ? estimate.to_i : '?'
end

#points_backgroundObject



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/pivotalprinter/story.rb', line 28

def points_background
  case points
    when '?' then 'cccccc'
    when  0  then 'ccff66'
    when  1  then '408000'
    when  2  then '808000'
    when  3  then 'ffcc66'
    when  5  then 'ff8000'
    when  8  then 'ff0000'
    else     'aa0000'
  end
end