Class: HQMF1::Expression
- Inherits:
-
Object
- Object
- HQMF1::Expression
- Includes:
- Utilities
- Defined in:
- lib/hqmf-parser/1.0/expression.rb
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(entry) ⇒ Expression
constructor
A new instance of Expression.
- #match_type ⇒ Object
- #to_json ⇒ Object
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) ⇒ Expression
Returns a new instance of Expression.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/hqmf-parser/1.0/expression.rb', line 9 def initialize(entry) @entry = entry @text = @entry.xpath('./*/cda:derivationExpr').text.strip type = attr_val('./*/cda:value/@xsi:type') case type when 'IVL_PQ' @value = Range.new(@entry.xpath('./*/cda:value')) when 'PQ' @value = Value.new(@entry.xpath('./*/cda:value')) when 'ANYNonNull' @value = HQMF::AnyValue.new when nil @value = HQMF::AnyValue.new else raise "Unknown expression value type #{type}" end @type = match_type end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
7 8 9 |
# File 'lib/hqmf-parser/1.0/expression.rb', line 7 def text @text end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/hqmf-parser/1.0/expression.rb', line 7 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/hqmf-parser/1.0/expression.rb', line 7 def value @value end |
Instance Method Details
#match_type ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hqmf-parser/1.0/expression.rb', line 28 def match_type case @text when /^COUNT(.*)$/ "COUNT" when /^MIN(.*)$/ "MIN" when /^MAX(.*)$/ "MAX" when /^DATEDIFF(.*)$/ "DATEDIFF" when /^TIMEDIFF(.*)$/ "TIMEDIFF" when /^MEDIAN(.*)$/ "MEDIAN" when /^AVG(.*)$/ "MEAN" else raise "unknown expression type: #{@text}" end end |
#to_json ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/hqmf-parser/1.0/expression.rb', line 49 def to_json json = build_hash(self, [:text,:type]) json[:value] = self.value.to_json if self.value json end |