Class: Slurper

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(story_file, options) ⇒ Slurper

Returns a new instance of Slurper.



21
22
23
24
25
# File 'lib/slurper.rb', line 21

def initialize(story_file, options)
  self.story_file = story_file
  self.update_epics = options[:update_epics]
  self.story_query = options[:story_query]
end

Instance Attribute Details

#storiesObject

Returns the value of attribute stories.



9
10
11
# File 'lib/slurper.rb', line 9

def stories
  @stories
end

#story_fileObject

Returns the value of attribute story_file.



9
10
11
# File 'lib/slurper.rb', line 9

def story_file
  @story_file
end

#story_queryObject

Returns the value of attribute story_query.



9
10
11
# File 'lib/slurper.rb', line 9

def story_query
  @story_query
end

#update_epicsObject

Returns the value of attribute update_epics.



9
10
11
# File 'lib/slurper.rb', line 9

def update_epics
  @update_epics
end

Class Method Details

.slurp(story_file, options) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/slurper.rb', line 11

def self.slurp(story_file, options)
  
  slurper = new(story_file, options)

  slurper.load_stories
  slurper.prepare_stories
  slurper.sort_stories(options[:reverse])
  slurper.create_stories
end

Instance Method Details

#create_storiesObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/slurper.rb', line 44

def create_stories
  puts "Preparing to slurp #{stories.size} stories into Tracker..."
  stories.each_with_index do |story, index|
    begin
      if story.save
        puts "#{index+1}. #{story.name}"
      else
        puts "Slurp failed. #{story.errors.full_messages}"
      end
    rescue ActiveResource::ConnectionError => e
      msg = "Slurp failed on story "
      if story.attributes["name"]
        msg << story.attributes["name"]
      else
        msg << "##{options[:reverse] ? index + 1 : stories.size - index }"
      end
      puts msg + ".  Error: #{e}"
    end
  end
end

#load_storiesObject



27
28
29
30
31
32
33
# File 'lib/slurper.rb', line 27

def load_stories
  if update_epics
    self.stories = Story.find_unlinked_epics(story_query)
  else
    self.stories = YAML.load(yamlize_story_file)
  end
end

#prepare_storiesObject



35
36
37
# File 'lib/slurper.rb', line 35

def prepare_stories
  stories.each { |story| story.prepare }
end

#sort_stories(reverse) ⇒ Object



39
40
41
42
# File 'lib/slurper.rb', line 39

def sort_stories(reverse)
  stories.sort!
  stories.reverse! unless reverse
end