Sha256: 08d520bd15a393d5a3bd8fce7f0c8d8c031fea6116d6625da89b8de9cc528525
Contents?: true
Size: 1.72 KB
Versions: 4
Compression:
Stored size: 1.72 KB
Contents
require 'activeresource' class Story < ActiveResource::Base @@defaults = YAML.load_file('story_defaults.yml') self.site = "http://www.pivotaltracker.com/services/v2/projects/#{@@defaults['project_id']}" headers['X-TrackerToken'] = @@defaults.delete("token") attr_accessor :story_lines def initialize(attributes = {}) @attributes = {} @prefix_options = {} load(@@defaults.merge(attributes)) end def parse(story_lines) @story_lines = story_lines parse_name parse_description parse_labels self end private def parse_name @story_lines.each_with_index do |line, i| if start_of_value?(line, 'name') if starts_with_whitespace?(@story_lines[i+1]) @attributes["name"] = @story_lines[i+1].strip else @attributes.delete("name") end end end end def parse_description @story_lines.each_with_index do |line, i| if start_of_value?(line, 'description') desc = Array.new while((next_line = @story_lines[i+=1]) && starts_with_whitespace?(next_line)) do desc << next_line end desc.empty? ? @attributes.delete("description") : @attributes["description"] = desc.join.gsub(/^ +/, "").gsub(/^\t+/, "") end end end def parse_labels @story_lines.each_with_index do |line, i| if start_of_value?(line, 'labels') if starts_with_whitespace?(@story_lines[i+1]) @attributes["labels"] = @story_lines[i+1].strip else @attributes.delete("labels") end end end end def starts_with_whitespace?(line) line && line[0,1] =~ /\s/ end def start_of_value?(line, attribute) line[0,attribute.size] == attribute end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
slurper-0.2.2 | lib/story.rb |
slurper-0.2.1 | lib/story.rb |
slurper-0.2.0 | lib/story.rb |
slurper-0.1.0 | lib/story.rb |