Class: HQMF::Converter::SimpleOperator
- Inherits:
-
Object
- Object
- HQMF::Converter::SimpleOperator
- Defined in:
- lib/hqmf-parser/converter/pass1/simple_operator.rb
Constant Summary collapse
- TEMPORAL =
'TEMPORAL'
- SUMMARY =
'SUMMARY'
- UNKNOWN =
'UNKNOWN'
- VALUE_FIELD_TIMES =
{ 'FACILITY_LOCATION_START' => 'FACILITY_LOCATION_ARRIVAL_DATETIME', 'FACILITY_LOCATION_END' => 'FACILITY_LOCATION_DEPARTURE_DATETIME' }
Instance Attribute Summary collapse
-
#category ⇒ Object
Returns the value of attribute category.
-
#field ⇒ Object
Returns the value of attribute field.
-
#field_code ⇒ Object
Returns the value of attribute field_code.
-
#field_time ⇒ Object
Returns the value of attribute field_time.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #field_value_key ⇒ Object
-
#initialize(category, type, value, field = nil, field_code = nil, field_time = nil) ⇒ SimpleOperator
constructor
A new instance of SimpleOperator.
- #summary? ⇒ Boolean
- #temporal? ⇒ Boolean
- #to_json ⇒ Object
Constructor Details
#initialize(category, type, value, field = nil, field_code = nil, field_time = nil) ⇒ SimpleOperator
Returns a new instance of SimpleOperator.
19 20 21 22 23 24 25 26 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 19 def initialize(category, type, value, field = nil, field_code=nil, field_time=nil) @category = category @type = type @value = value @field = field @field_code = field_code @field_time = field_time end |
Instance Attribute Details
#category ⇒ Object
Returns the value of attribute category.
17 18 19 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 17 def category @category end |
#field ⇒ Object
Returns the value of attribute field.
17 18 19 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 17 def field @field end |
#field_code ⇒ Object
Returns the value of attribute field_code.
17 18 19 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 17 def field_code @field_code end |
#field_time ⇒ Object
Returns the value of attribute field_time.
17 18 19 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 17 def field_time @field_time end |
#type ⇒ Object
Returns the value of attribute type.
17 18 19 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 17 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
17 18 19 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 17 def value @value end |
Class Method Details
.find_category(type) ⇒ Object
72 73 74 75 76 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 72 def self.find_category(type) return TEMPORAL if HQMF::TemporalReference::TYPES.include? type return SUMMARY if HQMF::SubsetOperator::TYPES.include? type return UNKNOWN end |
.parse_value(value) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 52 def self.parse_value(value) return nil unless value return value if value.is_a? String if (value[:value]) # values should be inclusive since we will be asking if it equals the value, ranther than being part of a range # if it's an offset we do not care that it is inclusive val = HQMF::Value.from_json(JSON.parse(value.to_json)) val.inclusive=true val elsif (value[:high] or value[:low]) HQMF::Range.from_json(JSON.parse(value.to_json)) elsif (value[:type] == 'CD') HQMF::Coded.from_json(JSON.parse(value.to_json)) elsif (value[:type] == 'ANYNonNull') HQMF::AnyValue.from_json(JSON.parse(value.to_json)) else raise "Unexpected value format: #{value.to_json}" end end |
Instance Method Details
#field_value_key ⇒ Object
45 46 47 48 49 50 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 45 def field_value_key key = HQMF::DataCriteria::VALUE_FIELDS[field_code] key = VALUE_FIELD_TIMES["#{key}_#{field_time.to_s.upcase}"] if (field_time) raise "unsupported field value: #{field_code}, #{field}" unless key key end |
#summary? ⇒ Boolean
31 32 33 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 31 def summary? category == SUMMARY end |
#temporal? ⇒ Boolean
28 29 30 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 28 def temporal? category == TEMPORAL end |
#to_json ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 35 def to_json json = {} json[:category] = @category if @category json[:type] = @type if @type json[:field] = @field if @field json[:field_code] = @field_code if @field_code json[:value] = @value.to_json if @value json end |