class HQMF2::Range
Represents a HQMF
physical quantity which can have low and high bounds
Attributes
high[RW]
low[RW]
width[RW]
Public Class Methods
new(entry, type = nil)
click to toggle source
# File lib/hqmf-parser/2.0/types.rb, line 116 def initialize(entry, type = nil) @type = type @entry = entry return unless @entry @low = optional_value("#{default_element_name}/cda:low", default_bounds_type) @high = optional_value("#{default_element_name}/cda:high", default_bounds_type) # Unset low bound to resolve verbose value bounds descriptions @low = nil if (@high.try(:value) && @high.value.to_i > 0) && (@low.try(:value) && @low.value.try(:to_i) == 0) @width = optional_value("#{default_element_name}/cda:width", 'PQ') end
Public Instance Methods
generate_any_value?(lm, hm)
click to toggle source
Check if are only AnyValue
elements for low and high
# File lib/hqmf-parser/2.0/types.rb, line 153 def generate_any_value?(lm, hm) (lm.nil? || lm.is_a?(HQMF::AnyValue)) && (hm.nil? || hm.is_a?(HQMF::AnyValue)) end
generate_value?(lm, hm)
click to toggle source
Check if the value for the range should actually produce a single value instead of a range (if low and high are the same)
# File lib/hqmf-parser/2.0/types.rb, line 159 def generate_value?(lm, hm) !lm.nil? && lm.try(:value) == hm.try(:value) && lm.try(:unit).nil? && hm.try(:unit).nil? end
to_model()
click to toggle source
Generates this classes hqmf-model equivalent
# File lib/hqmf-parser/2.0/types.rb, line 132 def to_model lm = low.try(:to_model) hm = high.try(:to_model) wm = width.try(:to_model) model_type = type if @entry.at_xpath('./cda:uncertainRange', HQMF2::Document::NAMESPACES) model_type = 'IVL_PQ' end if generate_any_value?(lm, hm) # Generate AnyValue if the only elements in the range are AnyValues. HQMF::AnyValue.new elsif generate_value?(lm, hm) # Generate a singel value if both low and high are the same HQMF::Value.new(lm.type, nil, lm.value, lm.inclusive?, lm.derived?, lm.expression) else HQMF::Range.new(model_type, lm, hm, wm) end end
type()
click to toggle source
# File lib/hqmf-parser/2.0/types.rb, line 127 def type @type || attr_val('./@xsi:type') end
Private Instance Methods
default_bounds_type()
click to toggle source
Sets up the default bound type as either time based or a physical quantity
# File lib/hqmf-parser/2.0/types.rb, line 191 def default_bounds_type case type when 'IVL_TS' 'TS' else 'PQ' end end
default_element_name()
click to toggle source
Defines how the time based element should be described
# File lib/hqmf-parser/2.0/types.rb, line 179 def default_element_name case type when 'IVL_PQ' '.' when 'IVL_TS' 'cda:phase' else 'cda:uncertainRange' end end
optional_value(xpath, type)
click to toggle source
Either derives a value from a specific path or generates a new value (or returns nil if none found)
# File lib/hqmf-parser/2.0/types.rb, line 166 def optional_value(xpath, type) value_def = @entry.at_xpath(xpath, HQMF2::Document::NAMESPACES) return unless value_def if value_def['flavorId'] == 'ANY.NONNULL' AnyValue.new else created_value = Value.new(value_def, type) # Return nil if no value was parsed created_value if created_value.try(:value) end end