class DailyReflection

Attributes

date[RW]

Public Class Methods

new(s=nil, debug: false, date: Date.today, period: :daily, title: "My click to toggle source
Calls superclass method
# File lib/daily_reflection.rb, line 13
def initialize(s=nil, debug: false, date: Date.today, 
              period: :daily, 
               title: "My #{period.to_s.capitalize} Reflection" )

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

  check_period_entry()

end

Public Instance Methods

add_entry(s) click to toggle source
# File lib/daily_reflection.rb, line 24
def add_entry(s)

  check_period_entry()

  e = Entry.new(@dxsx.dx.all.first)
  e.body = e.body + "\n" + s
  update_index(@dx.all.first, e.tags.join(' '))
  save_files()

end
create_day() click to toggle source
# File lib/daily_reflection.rb, line 40
def create_day()
  create_date_entry(@date)
end
create_month() click to toggle source
# File lib/daily_reflection.rb, line 53
def create_month()
  create_date_entry(Date.civil(@date.year, @date.month, -1))
end
create_week() click to toggle source
# File lib/daily_reflection.rb, line 44
def create_week()

  d = @date
  d += 1 until d.wday == 0     

  create_date_entry(d)                                                   

end
create_year() click to toggle source
# File lib/daily_reflection.rb, line 57
def create_year()
  create_date_entry(Date.new(@date.year+1,1,1)-1)
end
find_date(d) click to toggle source
# File lib/daily_reflection.rb, line 35
def find_date(d)
  self.find d.strftime("%-d %b %Y")    
end
today() click to toggle source
# File lib/daily_reflection.rb, line 61
def today()
  Entry.new(@dxsx.dx.all.first)
end

Private Instance Methods

check_period_entry() click to toggle source
# File lib/daily_reflection.rb, line 67
def check_period_entry()
  
  case @period.to_sym
  when :daily
    
    create_day() unless find_date(@date)
    
  when :weekly
    
    d = @date
    d += 1 until d.wday == 0   
    create_week() unless find_date(d)
    
  when :monthly
    
    d = Date.civil(@date.year, @date.month, -1)
    create_month() unless find_date(d)
    
  when :yearly
    
    create_year() unless find_date(Date.new(@date.year+1,1,1)-1)
    
  end
    
end
create_date_entry(d) click to toggle source
# File lib/daily_reflection.rb, line 93
def create_date_entry(d)
  self.create_section "# %s\n\n\n+ %s" % [d.strftime("%-d %b %Y"), d.year]
end