Class: Insulin::OnTrackNote

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

Overview

Class representing a single OnTrack note

Constant Summary collapse

@@keys =

Lookups. We will only deal with notes of these types

{
  "F" => 'food',
  "B" => 'booze',
  "N" => 'note'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(n) ⇒ OnTrackNote

Parse the raw note ā€˜nā€™



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
# File 'lib/insulin/on_track_note.rb', line 18

def initialize n

  # Key/value splits on ':'
  bits = n.split ":"

  # Remove leading/trailing cruft from key part
  t = bits[0].strip

  # We only deal with the keys we know about
  if @@keys.keys.include? t

    # Remove cruft from content, downcase
    @content = bits[1].strip.downcase

    # These keys mean we turn the content into a list
    if ["F", "B"].include? t
      a = []
      @content.split(",").each do |v|
        a << v.strip
      end
      @content = a
    end

    # Set key from lookup list
    @type = @@keys[t]
  end
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



15
16
17
# File 'lib/insulin/on_track_note.rb', line 15

def content
  @content
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'lib/insulin/on_track_note.rb', line 15

def type
  @type
end