Class: StripeLocal::Discount

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ObjectAdapter
Defined in:
app/models/stripe_local/discount.rb

Class Method Summary collapse

Class Method Details

.create(object) ⇒ Object



11
12
13
# File 'app/models/stripe_local/discount.rb', line 11

def create object
  super normalize object
end

.normalize(attrs) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/stripe_local/discount.rb', line 15

def normalize attrs
  attrs.each_with_object({}) do |(k,v),h|
    key = case k.to_sym
    when :customer then :customer_id
    when :coupon   then h[:coupon_id] = v.id and next
    when ->(x){ attribute_method? x } then k.to_sym
    else next
    end
    if v.is_a?(Numeric) && v > 1000000000
      h[key] = Time.at( v )
    else
      h[key] = v
    end
  end
end