Sha256: fef2ae05064291adb2ecf0e37c0541ddb31b37838def343bc17e4f9d628171b2

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'time'

module Pivotalprinter
  class Story
    FIELDS = [ :name, :id, :story_type, :estimate, :current_state, :description, :requested_by, :labels, :created_at, :updated_at ]
    attr_accessor *FIELDS
    
    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
    
    def self.open(ids)
      stories = ids.map do |id|
        response = Client.get "/projects/#{Client.project}/stories/#{id}"
        response = Nokogiri::XML.parse(response)
        self.new(response.css('story'))        
      end
    end
    
    def points
      estimate.to_i >= 0 ? estimate.to_i : '?'
    end
    
    def points_background
      case points
        when '?': 'cccccc'
        when  0: 'ccff66'
        when  1: '408000'
        when  2: '808000'
        when  3: 'ffcc66'
        when  5: 'ff8000'
        when  8: 'ff0000'
        else     'aa0000'
      end
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pivotalprinter-0.1.7 lib/pivotalprinter/story.rb