Class: Timekeeper::Keeper

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

Instance Method Summary collapse

Instance Method Details

#closeObject



17
18
19
# File 'lib/timekeeper/keeper.rb', line 17

def close
  table.close
end

#config(file = "timekeeper.yml") ⇒ Object



5
6
7
# File 'lib/timekeeper/keeper.rb', line 5

def config(file="timekeeper.yml")
  @config ||= YAML.load_file(file)
end

#countObject



21
22
23
# File 'lib/timekeeper/keeper.rb', line 21

def count
  table.count
end

#delete(id) ⇒ Object



9
10
11
# File 'lib/timekeeper/keeper.rb', line 9

def delete(id)
  table.delete(id)
end

#delete_allObject



13
14
15
# File 'lib/timekeeper/keeper.rb', line 13

def delete_all
  table.clear
end

#get(id) ⇒ Object



31
32
33
34
35
# File 'lib/timekeeper/keeper.rb', line 31

def get(id)
  if attributes = table.lget(id.to_s).values.first
    Keep.new(attributes)
  end
end

#store(attributes) ⇒ Object



25
26
27
28
29
# File 'lib/timekeeper/keeper.rb', line 25

def store(attributes)
  attributes.store("name", config["name"])
  attributes.store("date", Date.today) unless attributes["date"]
  table[table.genuid] = Keep.new(attributes).to_hash
end

#update(id, attributes_to_update) ⇒ Object



37
38
39
40
41
# File 'lib/timekeeper/keeper.rb', line 37

def update(id, attributes_to_update)
  if attributes = table.lget(id.to_s).values.first
    table[id] = Keep.new(attributes).update(attributes_to_update).to_hash
  end
end