Class: HQMF::Range

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

Overview

Represents a HQMF physical quantity which can have low and high bounds

Direct Known Subclasses

EffectiveTime

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(type, low, high, width) ⇒ Range

Create a new HQMF::Value

Parameters:



95
96
97
98
99
100
# File 'lib/hqmf-model/types.rb', line 95

def initialize(type,low,high,width)
  @type = type || 'IVL_PQ'
  @low = low
  @high = high
  @width = width
end

Instance Attribute Details

#highObject

Returns the value of attribute high.



88
89
90
# File 'lib/hqmf-model/types.rb', line 88

def high
  @high
end

#lowObject

Returns the value of attribute low.



88
89
90
# File 'lib/hqmf-model/types.rb', line 88

def low
  @low
end

#typeObject

Returns the value of attribute type.



88
89
90
# File 'lib/hqmf-model/types.rb', line 88

def type
  @type
end

#widthObject

Returns the value of attribute width.



88
89
90
# File 'lib/hqmf-model/types.rb', line 88

def width
  @width
end

Class Method Details

.from_json(json) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/hqmf-model/types.rb', line 102

def self.from_json(json)
  type = json["type"] if json["type"]
  low = HQMF::Value.from_json(json["low"]) if json["low"]
  high = HQMF::Value.from_json(json["high"]) if json["high"]
  width = HQMF::Value.from_json(json["width"]) if json["width"]
  
  HQMF::Range.new(type,low,high,width)
end

Instance Method Details

#==(other) ⇒ Object



136
137
138
# File 'lib/hqmf-model/types.rb', line 136

def ==(other)
  check_equality(self,other)
end

#stringifyObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/hqmf-model/types.rb', line 119

def stringify
  operator = ""
  if (@high && @low)
    if (@high.value == @low.value and @high.inclusive? and low.inclusive?)
      "#{@low.stringify}"
    else
      ">#{@low.stringify} and <#{@high.stringify}}"
    end
  elsif (@high)
    "<#{@high.stringify}"
  elsif (@low)
    ">#{@low.stringify}"
  else
    raise "cannot convert range to string"
  end
end

#to_jsonObject



111
112
113
114
115
116
117
# File 'lib/hqmf-model/types.rb', line 111

def to_json
  json = build_hash(self, [:type])
  json[:low] = self.low.to_json if self.low
  json[:high] = self.high.to_json if self.high
  json[:width] = self.width.to_json if self.width
  json
end