Class: ReminderFile

Inherits:
Object
  • Object
show all
Defined in:
lib/forgetful/extensions/csv/reminder_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, delay = 0..0) ⇒ ReminderFile

Returns a new instance of ReminderFile.



6
7
8
9
# File 'lib/forgetful/extensions/csv/reminder_file.rb', line 6

def initialize(filename, delay=0..0)
  @filename = filename
  @delay    = delay
end

Instance Attribute Details

#delayObject (readonly)

Returns the value of attribute delay.



4
5
6
# File 'lib/forgetful/extensions/csv/reminder_file.rb', line 4

def delay
  @delay
end

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/forgetful/extensions/csv/reminder_file.rb', line 4

def filename
  @filename
end

Instance Method Details

#readObject



11
12
13
14
15
# File 'lib/forgetful/extensions/csv/reminder_file.rb', line 11

def read
  File.open(filename) do |file|
    parse_csv(file)
  end
end

#write(reminders) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/forgetful/extensions/csv/reminder_file.rb', line 17

def write(reminders)
  data = CSV.generate do |csv|
           reminders.each do |reminder|
             csv << reminder.to_csv
           end
         end

  File.open(filename, "w") do |file|
    file.write(data)
  end
end