Class: OneUp::Ledger

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

Instance Method Summary collapse

Constructor Details

#initialize(repository: LedgerRepository) ⇒ Ledger

Returns a new instance of Ledger.



20
21
22
# File 'lib/one_up/ledger.rb', line 20

def initialize(repository: LedgerRepository)
  @repository = repository
end

Instance Method Details

#add_entry(giver:, receiver:, gift:, message:, created_at: Time.now) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/one_up/ledger.rb', line 24

def add_entry(giver:, receiver:, gift:, message:, created_at: Time.now)
  @repository.create(
    giver: giver,
    receiver: receiver,
    gift: gift,
    message: message,
    created_at: created_at
  )
end

#clear_repositoryObject



44
45
46
# File 'lib/one_up/ledger.rb', line 44

def clear_repository
  @repository.delete_all
end

#entriesObject



34
35
36
# File 'lib/one_up/ledger.rb', line 34

def entries
  @repository.all
end

#entries_todayObject



38
39
40
41
42
# File 'lib/one_up/ledger.rb', line 38

def entries_today
  today_start = Date.today.to_time
  today_end = (Date.today + 1).to_time - 1
  @repository.entries_from_range(today_start, today_end)
end