Module: Comable::Order::Morrisable::ClassMethods

Defined in:
app/models/comable/order/morrisable.rb

Instance Method Summary collapse

Instance Method Details

#morris_keysObject


7
8
9
# File 'app/models/comable/order/morrisable.rb', line 7

def morris_keys
  %w( count price )
end

#to_morrisObject


11
12
13
14
15
16
# File 'app/models/comable/order/morrisable.rb', line 11

def to_morris
  this = (Rails::VERSION::MAJOR == 3) ? scoped : all
  this.group_by { |order| order.completed_at.to_date }.map do |date, orders|
    { date: date, count: orders.count, price: orders.sum(&:total_price) }
  end.to_json
end