class ParseDose

Attributes

qty[R]
qty_range[R]
unit[RW]

Public Class Methods

new(qty = nil, unit = nil) click to toggle source
# File lib/oddb2xml/parslet_compositions.rb, line 299
def initialize(qty = nil, unit = nil)
  puts "ParseDose.new from #{qty.inspect} #{unit.inspect} #{unit.inspect}" if VERBOSE_MESSAGES
  if qty && (qty.is_a?(String) || qty.is_a?(Parslet::Slice))
    string = qty.to_s.delete("'")
    if string.index("-") && (string.index("-") > 0)
      @qty_range = string
    elsif string.index(/\^|\*|\//)
      @qty = string
    else
      @qty = string.index(".") ? string.to_f : string.to_i
    end
  elsif qty
    @qty = qty.eval
  else
    @qty = 1
  end
  @unit = unit ? unit.to_s : nil
end

Public Instance Methods

eval() click to toggle source
# File lib/oddb2xml/parslet_compositions.rb, line 318
def eval
  self
end
to_s() click to toggle source
# File lib/oddb2xml/parslet_compositions.rb, line 322
def to_s
  return @unit unless @qty || @qty_range
  res = "#{@qty}#{@qty_range}"
  res = "#{res} #{@unit}" if @unit
  res
end