-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added low level access to various product measurements
- weight, height, etc
- Loading branch information
Showing
6 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require 'bigdecimal' | ||
|
||
module ONIX | ||
|
||
class DecimalType < ROXML::XMLRef # ::nodoc:: | ||
attr_reader :cdata, :content | ||
|
||
def initialize(accessor, args, &block) | ||
super(accessor, args, &block) | ||
@content = args.content? | ||
@cdata = args.cdata? | ||
end | ||
|
||
# Updates the text in the given _xml_ block to | ||
# the _value_ provided. | ||
def update_xml(xml, value) | ||
parent = wrap(xml) | ||
if value.kind_of?(BigDecimal) | ||
value = value.to_s("F") | ||
else | ||
value = value.to_s | ||
end | ||
add(parent.child_add(LibXML::XML::Node.new_element(name)), value) | ||
xml | ||
end | ||
|
||
def value(xml) | ||
if content | ||
value = BigDecimal.new(xml.content) | ||
else | ||
child = xml.search(name).first | ||
value = BigDecimal.new(child.content) if child | ||
end | ||
block ? block.call(value) : value | ||
end | ||
|
||
private | ||
|
||
def add(dest, value) | ||
if cdata | ||
dest.child_add(LibXML::XML::Node.new_cdata(value.to_utf)) | ||
else | ||
dest.content = value.to_utf | ||
end | ||
end | ||
end | ||
end | ||
|
||
ROXML::TypeRegistry.register(:decimal, ONIX::DecimalType) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module ONIX | ||
class Measure | ||
include ROXML | ||
|
||
xml_accessor :measure_type_code, :twodigit, :from => "MeasureTypeCode" | ||
xml_accessor :measurement, :decimal, :from => "Measurement" | ||
xml_accessor :measure_unit_code, :etext, :from => "MeasureUnitCode" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters