Class: AdfBuilder::Price
- Inherits:
-
Object
- Object
- AdfBuilder::Price
- Defined in:
- lib/adf_builder/vehicles/price.rb
Constant Summary collapse
- VALID_PARAMETERS =
{ price: [:type, :currency, :delta, :relativeto, :source] }
- VALID_VALUES =
{ price: { type: %w[quote offer msrp invoice call appraisal asking], currency: true, delta: %w[absolute relative percentage], relativeto: %w[msrp invoice], source: true } }
Instance Method Summary collapse
-
#initialize(parent_node, value, params = {}) ⇒ Price
constructor
A new instance of Price.
- #update(value, params = {}) ⇒ Object
- #validate_currency(params) ⇒ Object
Constructor Details
#initialize(parent_node, value, params = {}) ⇒ Price
Returns a new instance of Price.
18 19 20 21 22 23 24 |
# File 'lib/adf_builder/vehicles/price.rb', line 18 def initialize(parent_node, value, params={}) @parent_node = parent_node params.merge!({valid_values: VALID_VALUES, valid_parameters: VALID_PARAMETERS}) validate_currency(params) AdfBuilder::Builder.update_node(@parent_node, :price, value, params) @price = @parent_node.price end |
Instance Method Details
#update(value, params = {}) ⇒ Object
26 27 28 29 |
# File 'lib/adf_builder/vehicles/price.rb', line 26 def update(value, params={}) params.merge!({valid_values: VALID_VALUES, valid_parameters: VALID_PARAMETERS}) AdfBuilder::Builder.update_node(@parent_node, :price, value, params) end |
#validate_currency(params) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/adf_builder/vehicles/price.rb', line 31 def validate_currency(params) code = params[:currency] if code json = JSON.parse(File.read('./lib/adf_builder/data/iso-4217-currency-codes.json')) codes = json.map{|j| j['Alphabetic_Code']}.reject{|j| j.nil?} unless codes.include? code params.delete(:currency) end end end |