Class: HQMF2::SubsetOperator
- Inherits:
-
Object
- Object
- HQMF2::SubsetOperator
- Includes:
- Utilities
- Defined in:
- lib/hqmf-parser/2.0/types.rb
Overview
Represents a subset of a specific group (the first in the group, the sum of the group, etc.)
Constant Summary collapse
- ORDER_SUBSETS =
%w(FIRST SECOND THIRD FOURTH FIFTH)
- LAST_SUBSETS =
%w(LAST RECENT)
- TIME_SUBSETS =
%w(DATEDIFF TIMEDIFF)
- QDM_TYPE_MAP =
{ 'QDM_LAST:' => 'RECENT', 'QDM_SUM:SUM' => 'COUNT' }
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#handle_value_definition ⇒ Object
Return the value definition (what to calculate it on) associated with this subset.
-
#initialize(entry) ⇒ SubsetOperator
constructor
A new instance of SubsetOperator.
-
#to_model ⇒ Object
Generates this classes hqmf-model equivalent.
-
#translate_type(subset_code, qdm_subset_code) ⇒ Object
Take a qdm type code to map it to a subset operator, or failing at finding that, return the given subset code.
Methods included from Utilities
#attr_val, attr_val, #strip_tokens, #to_xml
Methods included from HQMF::Conversion::Utilities
#build_hash, #check_equality, #json_array, #openstruct_to_json
Constructor Details
#initialize(entry) ⇒ SubsetOperator
Returns a new instance of SubsetOperator.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/hqmf-parser/2.0/types.rb', line 267 def initialize(entry) @entry = entry sequence_number = attr_val('./cda:sequenceNumber/@value') qdm_subset_code = attr_val('./qdm:subsetCode/@code') subset_code = attr_val('./cda:subsetCode/@code') if sequence_number @type = ORDER_SUBSETS[sequence_number.to_i - 1] else @type = translate_type(subset_code, qdm_subset_code) end value_def = handle_value_definition @value = HQMF2::Range.new(value_def, 'IVL_PQ') if value_def && !@value end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
261 262 263 |
# File 'lib/hqmf-parser/2.0/types.rb', line 261 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
261 262 263 |
# File 'lib/hqmf-parser/2.0/types.rb', line 261 def value @value end |
Instance Method Details
#handle_value_definition ⇒ Object
Return the value definition (what to calculate it on) associated with this subset. Other values, such as type and value, may be modified depending on this value.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/hqmf-parser/2.0/types.rb', line 285 def handle_value_definition value_def = @entry.at_xpath('./*/cda:repeatNumber', HQMF2::Document::NAMESPACES) unless value_def # TODO: HQMF needs better differentiation between SUM & COUNT... # currently using presence of repeatNumber... @type = 'SUM' if @type == 'COUNT' value_def = @entry.at_xpath('./*/cda:value', HQMF2::Document::NAMESPACES) end # TODO: Resolve extracting values embedded in criteria within outboundRel's if @type == 'SUM' value_def = @entry.at_xpath('./*/*/*/cda:value', HQMF2::Document::NAMESPACES) end if value_def value_type = value_def.at_xpath('./@xsi:type', HQMF2::Document::NAMESPACES) @value = HQMF2::AnyValue.new if String.try_convert(value_type) == 'ANY' end value_def end |
#to_model ⇒ Object
Generates this classes hqmf-model equivalent
318 319 320 321 |
# File 'lib/hqmf-parser/2.0/types.rb', line 318 def to_model vm = value ? value.to_model : nil HQMF::SubsetOperator.new(type, vm) end |
#translate_type(subset_code, qdm_subset_code) ⇒ Object
Take a qdm type code to map it to a subset operator, or failing at finding that, return the given subset code.
308 309 310 311 312 313 314 315 |
# File 'lib/hqmf-parser/2.0/types.rb', line 308 def translate_type(subset_code, qdm_subset_code) combined = "#{qdm_subset_code}:#{subset_code}" if QDM_TYPE_MAP[combined] QDM_TYPE_MAP[combined] else subset_code end end |