Class: RBook::Onix::SalesRestriction
- Inherits:
-
Object
- Object
- RBook::Onix::SalesRestriction
- Defined in:
- lib/rbook/onix/sales_restriction.rb
Instance Attribute Summary collapse
-
#detail ⇒ Object
Returns the value of attribute detail.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
-
.load_from_element(element) ⇒ Object
Attempts to create a contributor object using the supplied xml element.
- .load_from_string(str) ⇒ Object
Instance Method Summary collapse
- #to_element ⇒ Object
-
#to_s ⇒ Object
Return an XML string representing this contributor.
Instance Attribute Details
#detail ⇒ Object
Returns the value of attribute detail.
7 8 9 |
# File 'lib/rbook/onix/sales_restriction.rb', line 7 def detail @detail end |
#type ⇒ Object
Returns the value of attribute type.
7 8 9 |
# File 'lib/rbook/onix/sales_restriction.rb', line 7 def type @type end |
Class Method Details
.load_from_element(element) ⇒ Object
Attempts to create a contributor object using the supplied xml element
23 24 25 26 27 28 29 30 31 |
# File 'lib/rbook/onix/sales_restriction.rb', line 23 def SalesRestriction.load_from_element(element) raise ArgumentError, 'load_from_element expects a REXML element object' unless element.class == REXML::Element if REXML::XPath.first(element, '//SalesRestriction').nil? raise LoadError, 'supplied REXML document object does not appear contain a valid SalesRestriction fragment' end self.load_from_string(element.to_s) end |
.load_from_string(str) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rbook/onix/sales_restriction.rb', line 9 def self.load_from_string(str) doc = Hpricot::XML(str) restriction = SalesRestriction.new tmp = doc.search('//SalesRestriction/SalesRestrictionType') restriction.type = tmp.inner_html unless tmp.inner_html.blank? tmp = doc.search('//SalesRestriction/SalesRestrictionDetail') restriction.detail = tmp.inner_html unless tmp.inner_html.blank? return restriction end |
Instance Method Details
#to_element ⇒ Object
46 47 48 |
# File 'lib/rbook/onix/sales_restriction.rb', line 46 def to_element REXML::Document.new(to_s).root end |
#to_s ⇒ Object
Return an XML string representing this contributor
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rbook/onix/sales_restriction.rb', line 34 def to_s raise 'SalesRestriction must have a type to create an element' if self.type.nil? raise 'Contributor must have a detail to create an element' if self.detail.nil? builder = Builder::XmlMarkup.new(:indent => 2) builder.SalesRestriction do |sr| sr.SalesRestrictionType self.type sr.SalesRestrictionDetail self.detail end end |