Module: LlmCostTracker::Ledger::Period

Defined in:
lib/llm_cost_tracker/ledger/period.rb,
lib/llm_cost_tracker/ledger/period/totals.rb

Defined Under Namespace

Classes: Totals

Constant Summary collapse

PERIODS =
{
  month: "month",
  day:   "day"
}.freeze

Class Method Summary collapse

Class Method Details

.bucket(period, time) ⇒ Object



26
27
28
# File 'lib/llm_cost_tracker/ledger/period.rb', line 26

def bucket(period, time)
  range_start(period, time).to_date
end

.range_start(period, time) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/llm_cost_tracker/ledger/period.rb', line 17

def range_start(period, time)
  utc_time = time.to_time.utc

  case period
  when :month then utc_time.beginning_of_month
  when :day then utc_time.beginning_of_day
  end
end

.valid_keys(periods) ⇒ Object



13
14
15
# File 'lib/llm_cost_tracker/ledger/period.rb', line 13

def valid_keys(periods)
  periods.select { |period| PERIODS.key?(period) }
end