Class: HQMF::OperatorConverter
- Inherits:
-
Object
- Object
- HQMF::OperatorConverter
- Defined in:
- lib/hqmf-parser/converter/pass2/operator_converter.rb
Overview
Class for converting an HQMF 1.0 representation to an HQMF 2.0 representation
Class Method Summary collapse
- .apply_summary(data_criteria, precondition, restriction, data_criteria_converter) ⇒ Object
- .apply_temporal(data_criteria, precondition, restriction, data_criteria_converter) ⇒ Object
Class Method Details
.apply_summary(data_criteria, precondition, restriction, data_criteria_converter) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/hqmf-parser/converter/pass2/operator_converter.rb', line 59 def self.apply_summary(data_criteria, precondition, restriction, data_criteria_converter) value = restriction.operator.value type = restriction.operator.type subset_operator = HQMF::SubsetOperator.new(type, value) if (restriction.multi_target?) children_criteria = HQMF::DataCriteriaConverter.extract_data_criteria(restriction.preconditions, data_criteria_converter) data_criteria = nil if (children_criteria.length == 1) data_criteria = children_criteria[0] data_criteria.subset_operators ||= [] # add subset operator to data criteria data_criteria.subset_operators << subset_operator unless data_criteria.has_subset(subset_operator) else parent_id = "GROUP" if restriction.generated_data_criteria.nil? # we pass in restriction.preconditions here rather than children_criteria because we need to be able to create grouping data criteria for and and or preconditions in a tree data_criteria = data_criteria_converter.create_group_data_criteria(restriction.preconditions, type, value, parent_id, HQMF::Counter.instance.next, "grouping", "summary") # save the generated grouping criteria so that we can reference it from other locations restriction.generated_data_criteria = data_criteria else # we have already processed this restriction and have a grouping criteria for it. Take the one we have previously generated data_criteria = restriction.generated_data_criteria end data_criteria.subset_operators ||= [] # add subset operator to data criteria data_criteria.subset_operators << subset_operator unless data_criteria.has_subset(subset_operator) end precondition.reference = HQMF::Reference.new(data_criteria.id) elsif (restriction.single_target?) subset_operator = HQMF::SubsetOperator.new(type, value) data_criteria.subset_operators ||= [] # add subset operator to data criteria data_criteria.subset_operators << subset_operator unless data_criteria.has_subset(subset_operator) end restriction.converted=true end |
.apply_temporal(data_criteria, precondition, restriction, data_criteria_converter) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hqmf-parser/converter/pass2/operator_converter.rb', line 5 def self.apply_temporal(data_criteria, precondition, restriction, data_criteria_converter) data_criteria.temporal_references ||= [] value = restriction.operator.value type = restriction.operator.type temporal_reference = nil if (restriction.single_target?) # multiple targets appears to be the result of restrictions with restrictions target = restriction.target if (restriction.multi_target?) found = false # restrictions with restrictions can have a target that is modified by the child restrcitons restriction.preconditions.each do |precondition| if precondition.reference.id.start_with? target found = true target = precondition.reference.id end end unless found puts "\tmultiple targets... need to check this" if restriction.multi_target? end end temporal_reference = HQMF::TemporalReference.new(type, HQMF::Reference.new(target),value) data_criteria_converter.validate_not_deleted(target) elsif (restriction.multi_target?) children_criteria = HQMF::DataCriteriaConverter.extract_data_criteria(restriction.preconditions, data_criteria_converter) if (children_criteria.length == 1) target = children_criteria[0].id temporal_reference = HQMF::TemporalReference.new(type, HQMF::Reference.new(target),value) data_criteria_converter.validate_not_deleted(target) else parent_id = "GROUP" if restriction.generated_data_criteria.nil? # we pass in restriction.preconditions here rather than children_criteria because we need to be able to create grouping data criteria for and and or preconditions in a tree group_criteria = data_criteria_converter.create_group_data_criteria(restriction.preconditions, "#{type}_CHILDREN", value, parent_id, HQMF::Counter.instance.next, "grouping", "temporal") # save the generated grouping criteria so that we can reference it from other locations restriction.generated_data_criteria = group_criteria else # we have already processed this restriction and have a grouping criteria for it. Take the one we have previously generated group_criteria = restriction.generated_data_criteria end temporal_reference = HQMF::TemporalReference.new(type, HQMF::Reference.new(group_criteria.id), value) end else raise "no target for temporal restriction" end restriction.converted=true # add temporal reference to data criteria data_criteria.temporal_references << temporal_reference unless data_criteria.has_temporal(temporal_reference) end |