Class: TitlePage::Price

Inherits:
Response show all
Defined in:
lib/titlepage/utils.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#price_amountObject

Returns the value of attribute price_amount.



122
123
124
# File 'lib/titlepage/utils.rb', line 122

def price_amount
  @price_amount
end

#price_type_codeObject

Returns the value of attribute price_type_code.



121
122
123
# File 'lib/titlepage/utils.rb', line 121

def price_type_code
  @price_type_code
end

Class Method Details

.from_xml(node) ⇒ Object

convert a nokogiri node to a TitlePage::Price object



126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/titlepage/utils.rb', line 126

def self.from_xml(node)
  return nil if node.nil?
  #<Price xsi:type="tns:Price">
  #  <PriceAmount xsi:type="xsd:decimal">24.95</PriceAmount>
  #</Price>
  price = self.new
  price.price_type_code = node.xpath("//Price/PriceTypeCode/text()").first.andand.to_s
  val = node.xpath("//Price/PriceAmount/text()").first.andand.to_s
  val = val.gsub(/[^\d\.]/,"") # strip any extra chars (like commas)
  price.price_amount = BigDecimal.new(val) if val.size > 0
  price
end