class HQMF::Range

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

Attributes

high[RW]
low[RW]
type[RW]
width[RW]

Public Class Methods

from_json(json) click to toggle source
# 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
new(type,low,high,width) click to toggle source

Create a new HQMF::Value @param [String] type @param [Value] low @param [Value] high @param [Value] width

# 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

Public Instance Methods

==(other) click to toggle source
# File lib/hqmf-model/types.rb, line 135
def ==(other)
  check_equality(self,other)
end
stringify() click to toggle source
# File lib/hqmf-model/types.rb, line 119
def stringify
  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_json() click to toggle source
# 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