Class: StatsRepository

Inherits:
DefaultRepository show all
Defined in:
app/repositories/stats_repository.rb

Instance Attribute Summary

Attributes inherited from DefaultRepository

#klass

Instance Method Summary collapse

Methods inherited from DefaultRepository

#all, #create, #find, #find_all, #find_or_initialize, #initialize, #new

Constructor Details

This class inherits a constructor from DefaultRepository

Instance Method Details

#update_prices_for_today(price) ⇒ Object


2
3
4
5
6
7
8
9
# File 'app/repositories/stats_repository.rb', line 2

def update_prices_for_today(price)
  stats = find_or_initialize(created_at: Time.now.beginning_of_day..Time.now.end_of_day)
  stats.min_price_low = price if price < stats.min_price_low || stats.min_price_low == 0
  stats.min_price_high = price if price > stats.min_price_high || stats.min_price_high == 0
  stats.save if stats.changed?

  stats
end