Class: HQMF::Converter::SimpleOperator

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#categoryObject

Returns the value of attribute category.



17
18
19
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 17

def category
  @category
end

#fieldObject

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_codeObject

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_timeObject

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

#typeObject

Returns the value of attribute type.



17
18
19
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 17

def type
  @type
end

#valueObject

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_keyObject



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

Returns:

  • (Boolean)


31
32
33
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 31

def summary?
  category == SUMMARY
end

#temporal?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/hqmf-parser/converter/pass1/simple_operator.rb', line 28

def temporal?
  category == TEMPORAL
end

#to_jsonObject



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