Class: FriendlyShipping::Services::Ups::ParseModifierElement

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/services/ups/parse_modifier_element.rb

Class Method Summary collapse

Class Method Details

.call(element, currency_code:) ⇒ Array<String, Money>

Parameters:

  • element (Nokogiri::XML::Element)

    The modifier element from the source XML

  • currency_code (String)

    The currency code for this modifier's amount (i.e. 'USD')

Returns:

  • (Array<String, Money>)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/friendly_shipping/services/ups/parse_modifier_element.rb', line 10

def self.call(element, currency_code:)
  return unless element

  amount = element.at('Amount').text.to_d
  return if amount.zero?

  currency = Money::Currency.new(currency_code)
  amount = Money.new(amount * currency.subunit_to_unit, currency)

  modifier_type = element.at('ModifierType').text
  modifier_description = element.at('ModifierDesc').text

  label = "#{modifier_type} (#{modifier_description})"

  [label, amount]
end