Class: Ruby::Pomodoro::Tasks::Resource

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ruby/pomodoro/tasks/resource.rb

Class Method Summary collapse

Class Method Details

.allObject



21
22
23
# File 'lib/ruby/pomodoro/tasks/resource.rb', line 21

def all
  store.values
end

.create(attributes) ⇒ Object



10
11
12
13
14
15
# File 'lib/ruby/pomodoro/tasks/resource.rb', line 10

def create(attributes)
  id = store.size.next
  Entity.new(id: id, **attributes.slice(:name, :spent_time)).tap do |task|
    store[id] = task
  end
end

.delete_allObject



25
26
27
# File 'lib/ruby/pomodoro/tasks/resource.rb', line 25

def delete_all
  store.clear
end

.find(id) ⇒ Object



17
18
19
# File 'lib/ruby/pomodoro/tasks/resource.rb', line 17

def find(id)
  store[id]
end

.sum(attribute) ⇒ Object



29
30
31
# File 'lib/ruby/pomodoro/tasks/resource.rb', line 29

def sum(attribute)
  all.inject(0) { |sum, task| sum + task.public_send(attribute).to_i }
end