Class: Timert::Database

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

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Database

Returns a new instance of Database.



7
8
9
# File 'lib/timert/database.rb', line 7

def initialize(file)
  @file = file
end

Instance Method Details

#day(date = Date.today) ⇒ Object



15
16
17
# File 'lib/timert/database.rb', line 15

def day(date = Date.today)
  hash_to_day(load_data[key(date)], date)
end

#days(range) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/timert/database.rb', line 19

def days(range)
  entries = load_data
  result = []
  entries.each_pair do |date, day_hash|
    day = hash_to_day(day_hash, Time.at(date.to_i).to_date)
    if range.include?(day.date)
      result << day
    end
  end
  result
end

#save(day) ⇒ Object



31
32
33
34
35
# File 'lib/timert/database.rb', line 31

def save(day)
  current_data = load_data
  current_data[key(day.date)] = day.to_hash
  save_data(current_data)
end

#todayObject



11
12
13
# File 'lib/timert/database.rb', line 11

def today
  day
end