Class: MonthlyPlanner

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename = 'monthly-planner.txt', path: '.', today: Date.today) ⇒ MonthlyPlanner

Returns a new instance of MonthlyPlanner.



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

def initialize(filename='monthly-planner.txt', path: '.', today: Date.today)

  # is it a Dynarex file
  s, type = RXFHelper.read(filename)

  return @dx = Dynarex.new(s) if type == :url or s =~ /^</

  @filename, @path = filename, path
  
  fpath = File.join(path, filename)
  
  if File.exists?(fpath) then

    @dx = import_to_dx(File.read(fpath))    
    sync_archive(@dx.all)

    # purge any past dates
    @dx.all.reject! {|x| x.date < today}
        
  else
    @dx = new_dx    
  end
end

Instance Attribute Details

#to_sObject (readonly)

Returns the value of attribute to_s.



30
31
32
# File 'lib/monthly_planner.rb', line 30

def to_s
  @to_s
end

Instance Method Details

#dxObject



56
57
58
# File 'lib/monthly_planner.rb', line 56

def dx()
  @dx
end

#save(filename = @filename) ⇒ Object



60
61
62
63
64
65
66
# File 'lib/monthly_planner.rb', line 60

def save(filename=@filename)

  s = File.basename(filename) + "\n" + dx_to_s(@dx).lines[1..-1].join
  File.write File.join(@path, filename), s
  @dx.save File.join(@path, filename.sub(/\.txt$/,'.xml'))
      
end

#this_weekObject



68
69
70
71
72
# File 'lib/monthly_planner.rb', line 68

def this_week()
  
  @dx.all.select {|x|  x.date < Date.today + 7 }

end