Class: DailyReflection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s, debug: false, date: Date.today, title: 'My Daily Reflection') ⇒ DailyReflection

Returns a new instance of DailyReflection.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/daily_reflection.rb', line 12

def initialize(s, debug: false, date: Date.today, 
              title: 'My Daily Reflection')

  @date = date
  super(s, order: 'descending', debug: debug, title: title)

  # if the section for today doesn't exist create it

  create_day() unless found_today()

end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



10
11
12
# File 'lib/daily_reflection.rb', line 10

def date
  @date
end

Instance Method Details

#add_entry(s) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/daily_reflection.rb', line 24

def add_entry(s)

  create_day() unless found_today()

  rx = @dxsx.dx.all.first
  lines = rx.x.lines
  lines.insert -3, s + "\n"
  rx.x = lines.join

end

#create_dayObject



41
42
43
44
45
46
# File 'lib/daily_reflection.rb', line 41

def create_day()

  date = @date.strftime("%-d %b %Y")
  self.create_section "# %s\n\n\n+ %s" % [date, @date.year]

end

#find_todayObject Also known as: found_today



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

def find_today()
  self.find @date.strftime("%-d %b %Y")
end

#todayObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/daily_reflection.rb', line 48

def today()

  rx = @dxsx.dx.all.first

  def rx.body()
    x.lines[1..-2].join.strip
  end

  def rx.body=(s)
    text_entry = "%s\n\n%s\n\n%s" % [self.heading, s, self.footer]
    self.x = text_entry
  end

  def rx.footer()
    x.lines.last.chomp
  end

  def rx.footer=(s)
    a = x.lines
    a[-1] = s
    self.x = a.join
  end

  def rx.heading()
    x.lines.first.chomp
  end

  def rx.tags()
    footer[1..-1].strip.split
  end

  rx

end