Class: HQMF::Attribute

Inherits:
Object
  • Object
show all
Includes:
Conversion::Utilities
Defined in:
lib/hqmf-model/attribute.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Conversion::Utilities

#build_hash, #check_equality, #json_array, #openstruct_to_json

Constructor Details

#initialize(id, code, value, unit, name, id_obj = nil, code_obj = nil, value_obj = nil) ⇒ Attribute

Returns a new instance of Attribute.

Parameters:



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hqmf-model/attribute.rb', line 13

def initialize(id,code,value,unit,name,id_obj=nil,code_obj=nil,value_obj=nil)
  @id = id
  @code = code
  @value = value
  @unit = unit
  @name = name
  # enhanced model
  @id_obj = id_obj
  @code_obj = code_obj
  @value_obj = value_obj
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/hqmf-model/attribute.rb', line 4

def code
  @code
end

#code_objObject (readonly)

Returns the value of attribute code_obj.



4
5
6
# File 'lib/hqmf-model/attribute.rb', line 4

def code_obj
  @code_obj
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/hqmf-model/attribute.rb', line 4

def id
  @id
end

#id_objObject (readonly)

Returns the value of attribute id_obj.



4
5
6
# File 'lib/hqmf-model/attribute.rb', line 4

def id_obj
  @id_obj
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/hqmf-model/attribute.rb', line 4

def name
  @name
end

#unitObject (readonly)

Returns the value of attribute unit.



4
5
6
# File 'lib/hqmf-model/attribute.rb', line 4

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



4
5
6
# File 'lib/hqmf-model/attribute.rb', line 4

def value
  @value
end

#value_objObject (readonly)

Returns the value of attribute value_obj.



4
5
6
# File 'lib/hqmf-model/attribute.rb', line 4

def value_obj
  @value_obj
end

Class Method Details

.from_json(json) ⇒ Object



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
# File 'lib/hqmf-model/attribute.rb', line 25

def self.from_json(json)
  json = json.with_indifferent_access

  id = json["id"] if json["id"]
  code = json["code"] if json["code"]
  value = json["value"] if json["value"]
  unit = json["unit"] if json["unit"]
  name = json["name"] if json["name"]
  # enhanced model
  id_obj = HQMF::Identifier::from_json(json["id_obj"]) if json["id_obj"]
  code_obj = HQMF::Coded::from_json(json["code_obj"]) if json["code_obj"]
  value_obj = nil
  if (json["value_obj"])
    json_value = json["value_obj"].with_indifferent_access
    case json_value["type"]
    when 'II'
      value_obj = HQMF::Identifier::from_json(json_value)
    when 'CD'
      value_obj = HQMF::Coded::from_json(json_value)
    when 'ED'
      value_obj = HQMF::ED::from_json(json_value)
    else
      value_obj = json_value["value"].nil? ? HQMF::AnyValue::from_json(json_value) : HQMF::GenericValueContainer::from_json(json_value)
    end
  end

  HQMF::Attribute.new(id,code,value,unit,name,id_obj,code_obj,value_obj)
end

Instance Method Details

#to_jsonObject



54
55
56
57
58
59
60
# File 'lib/hqmf-model/attribute.rb', line 54

def to_json
  json = build_hash(self, [:id,:code,:value,:unit,:name])
  json[:id_obj] = @id_obj.to_json if @id_obj
  json[:code_obj] = @code_obj.to_json if @code_obj
  json[:value_obj] = @value_obj.to_json if @value_obj
  json
end