Class: HQMF1::Attribute
- Inherits:
-
Object
- Object
- HQMF1::Attribute
- Includes:
- Utilities
- Defined in:
- lib/hqmf-parser/1.0/attribute.rb
Overview
Represents a HQMF measure attribute
Instance Method Summary collapse
-
#code ⇒ String
Get the attribute code.
-
#const_name ⇒ Object
Get a JS friendly constant name for this measure attribute.
-
#id ⇒ String
Get the attribute id, used elsewhere in the document to refer to the attribute.
-
#initialize(entry) ⇒ Attribute
constructor
Create a new instance based on the supplied HQMF.
-
#name ⇒ String
Get the attribute name.
- #to_json ⇒ Object
-
#unit ⇒ String
Get the unit of the attribute value or nil if none is defined.
-
#value ⇒ String
Get the attribute value.
Methods included from Utilities
#attr_val, #check_nil_conjunction_on_child, #clean_json, #clean_json_recursive
Methods included from HQMF::Conversion::Utilities
#build_hash, #check_equality, #json_array, #openstruct_to_json
Constructor Details
#initialize(entry) ⇒ Attribute
Create a new instance based on the supplied HQMF
9 10 11 |
# File 'lib/hqmf-parser/1.0/attribute.rb', line 9 def initialize(entry) @entry = entry end |
Instance Method Details
#code ⇒ String
Get the attribute code
15 16 17 18 19 20 21 |
# File 'lib/hqmf-parser/1.0/attribute.rb', line 15 def code if (@entry.at_xpath('./cda:code/@code')) @entry.at_xpath('./cda:code/@code').value elsif @entry.at_xpath('./cda:code/@nullFlavor') @entry.at_xpath('./cda:code/@nullFlavor').value end end |
#const_name ⇒ Object
Get a JS friendly constant name for this measure attribute
58 59 60 61 |
# File 'lib/hqmf-parser/1.0/attribute.rb', line 58 def const_name components = name.gsub(/\W/,' ').split.collect {|word| word.strip.upcase } components.join '_' end |
#id ⇒ String
Get the attribute id, used elsewhere in the document to refer to the attribute
35 36 37 |
# File 'lib/hqmf-parser/1.0/attribute.rb', line 35 def id attr_val('./cda:id/@root') end |
#name ⇒ String
Get the attribute name
25 26 27 28 29 30 31 |
# File 'lib/hqmf-parser/1.0/attribute.rb', line 25 def name if (@entry.at_xpath('./cda:code/@displayName')) @entry.at_xpath('./cda:code/@displayName').value elsif @entry.at_xpath('cda:code/cda:originalText') @entry.at_xpath('cda:code/cda:originalText').text end end |
#to_json ⇒ Object
63 64 65 |
# File 'lib/hqmf-parser/1.0/attribute.rb', line 63 def to_json {self.const_name => build_hash(self, [:code,:value,:unit,:name,:id])} end |
#unit ⇒ String
Get the unit of the attribute value or nil if none is defined
53 54 55 |
# File 'lib/hqmf-parser/1.0/attribute.rb', line 53 def unit attr_val('./cda:value/@unit') end |
#value ⇒ String
Get the attribute value
41 42 43 44 45 46 47 48 49 |
# File 'lib/hqmf-parser/1.0/attribute.rb', line 41 def value val = attr_val('./cda:value/@value') val ||= attr_val('./cda:value/@extension') if val val else @entry.at_xpath('./cda:value').inner_text end end |