Class: Insulin::OnTrack::NoteSet

Inherits:
Hash
  • Object
show all
Defined in:
lib/insulin/on_track/note_set.rb

Overview

This class represents a set of notes

Instance Method Summary collapse

Constructor Details

#initialize(s) ⇒ NoteSet

Parse the string ā€˜sā€™



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/insulin/on_track/note_set.rb', line 11

def initialize s

  # Notes separated by newlines
  l = s.split"\n"

  # For each line
  l.each do |n|

    # Make a note
    x = Note.new n

    # This field will only exists for notes of a valid type
    if x.type

      # If we don't yet have this key
      if not self[x.type]

        # If the content is a list
        if x.content.class.name == "Array"

          # This becomes our value
          self[x.type] = x.content
        else

          # Otherwise make it onto a list
          self[x.type] = [x.content]
        end
      else

        # This key exists, so we append this value
        self[x.type] << x.content
      end
    end
  end
end