Class: Io::Flow::V0::Models::PriceEquation

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ PriceEquation

Returns a new instance of PriceEquation.



44678
44679
44680
44681
44682
44683
44684
44685
44686
44687
44688
44689
44690
44691
44692
44693
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44678

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:contracted_rate, :rate, :pricing, :base_price, :discount, :fixed_margin, :percent_margin, :insurance, :freight], 'PriceEquation')
  @contracted_rate = HttpClient::Preconditions.assert_class('contracted_rate', HttpClient::Helper.to_big_decimal(opts.delete(:contracted_rate)), BigDecimal)
  @rate = HttpClient::Preconditions.assert_class('rate', HttpClient::Helper.to_big_decimal(opts.delete(:rate)), BigDecimal)
  @pricing = (x = opts.delete(:pricing); x.is_a?(::Io::Flow::V0::Models::Pricing) ? x : ::Io::Flow::V0::Models::Pricing.new(x))
  @base_price = HttpClient::Preconditions.assert_class('base_price', HttpClient::Helper.to_big_decimal(opts.delete(:base_price)), BigDecimal)
  @discount = HttpClient::Preconditions.assert_class('discount', HttpClient::Helper.to_big_decimal(opts.delete(:discount)), BigDecimal)
  @fixed_margin = HttpClient::Preconditions.assert_class('fixed_margin', HttpClient::Helper.to_big_decimal(opts.delete(:fixed_margin)), BigDecimal)
  @percent_margin = HttpClient::Preconditions.assert_class('percent_margin', HttpClient::Helper.to_big_decimal(opts.delete(:percent_margin)), BigDecimal)
  @insurance = HttpClient::Preconditions.assert_class('insurance', HttpClient::Helper.to_big_decimal(opts.delete(:insurance)), BigDecimal)
  @freight = HttpClient::Preconditions.assert_class('freight', HttpClient::Helper.to_big_decimal(opts.delete(:freight)), BigDecimal)
  @duty = (x = opts.delete(:duty); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Duty) ? x : ::Io::Flow::V0::Models::Duty.new(x)))
  @tax = (x = opts.delete(:tax); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Tax) ? x : ::Io::Flow::V0::Models::Tax.new(x)))
  @percent_sales_margin = HttpClient::Preconditions.assert_class('percent_sales_margin', HttpClient::Helper.to_big_decimal((x = opts.delete(:percent_sales_margin); x.nil? ? 0 : x)), BigDecimal)
end

Instance Attribute Details

#base_priceObject (readonly)

Returns the value of attribute base_price.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def base_price
  @base_price
end

#contracted_rateObject (readonly)

Returns the value of attribute contracted_rate.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def contracted_rate
  @contracted_rate
end

#discountObject (readonly)

Returns the value of attribute discount.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def discount
  @discount
end

#dutyObject (readonly)

Returns the value of attribute duty.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def duty
  @duty
end

#fixed_marginObject (readonly)

Returns the value of attribute fixed_margin.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def fixed_margin
  @fixed_margin
end

#freightObject (readonly)

Returns the value of attribute freight.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def freight
  @freight
end

#insuranceObject (readonly)

Returns the value of attribute insurance.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def insurance
  @insurance
end

#percent_marginObject (readonly)

Returns the value of attribute percent_margin.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def percent_margin
  @percent_margin
end

#percent_sales_marginObject (readonly)

Returns the value of attribute percent_sales_margin.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def percent_sales_margin
  @percent_sales_margin
end

#pricingObject (readonly)

Returns the value of attribute pricing.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def pricing
  @pricing
end

#rateObject (readonly)

Returns the value of attribute rate.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def rate
  @rate
end

#taxObject (readonly)

Returns the value of attribute tax.



44676
44677
44678
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44676

def tax
  @tax
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



44699
44700
44701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44699

def copy(incoming={})
  PriceEquation.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hashObject



44703
44704
44705
44706
44707
44708
44709
44710
44711
44712
44713
44714
44715
44716
44717
44718
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44703

def to_hash
  {
    :contracted_rate => contracted_rate.to_f.to_s,
    :rate => rate.to_f.to_s,
    :pricing => pricing.to_hash,
    :base_price => base_price.to_f.to_s,
    :discount => discount.to_f.to_s,
    :fixed_margin => fixed_margin.to_f.to_s,
    :percent_margin => percent_margin.to_f.to_s,
    :insurance => insurance.to_f.to_s,
    :freight => freight.to_f.to_s,
    :duty => duty.nil? ? nil : duty.to_hash,
    :tax => tax.nil? ? nil : tax.to_hash,
    :percent_sales_margin => percent_sales_margin.to_f.to_s
  }
end

#to_jsonObject



44695
44696
44697
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 44695

def to_json
  JSON.dump(to_hash)
end