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(note_file) ⇒ Slurper

Returns a new instance of Slurper.



16
17
18
# File 'lib/slurper.rb', line 16

def initialize(note_file)
  self.note_file = note_file
end

Instance Attribute Details

#note_fileObject

Returns the value of attribute note_file.



5
6
7
# File 'lib/slurper.rb', line 5

def note_file
  @note_file
end

#notesObject

Returns the value of attribute notes.



5
6
7
# File 'lib/slurper.rb', line 5

def notes
  @notes
end

Class Method Details

.slurp(note_file, reverse, tag) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/slurper.rb', line 7

def self.slurp(note_file, reverse, tag)
  slurper = new(note_file)
  Note.config
  slurper.load_notes
  slurper.prepare_notes
  slurper.notes.reverse! unless reverse
  slurper.create_notes(tag)
end

Instance Method Details

#create_notes(tag) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/slurper.rb', line 28

def create_notes(tag)
  puts "Preparing to slurp #{notes.size} notes into ProjectNotifier..."
  notes.each_with_index do |note, index|
    begin
      unless tag.nil?
        tags = note.tag_list || ""
        list_of_tags = tags.split(",")
        tag.split(",").each do |tag_param|
          list_of_tags << tag_param
        end
        
        note.tag_list = list_of_tags.join(",")
      end
      if note.save  
        puts "#{index+1}. #{note.subject}"
      else
        puts "Slurp failed. #{note.errors.full_messages}"
      end
    rescue ActiveResource::ConnectionError => e
      msg = "Slurp failed on note "
      if note.attributes["subject"]
        msg << note.attributes["subject"]
      else
        msg << "##{options[:reverse] ? index + 1 : notes.size - index }"
      end
      puts msg + ".  Error: #{e}"
    end
  end
end

#load_notesObject



20
21
22
# File 'lib/slurper.rb', line 20

def load_notes
  self.notes = YAML.load(yamlize_note_file)
end

#prepare_notesObject



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

def prepare_notes
  notes.each { |note| note.prepare }
end