Class: ParseDose

Inherits:
Object
  • Object
show all
Defined in:
lib/oddb2xml/parslet_compositions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(qty = nil, unit = nil) ⇒ ParseDose



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
# File 'lib/oddb2xml/parslet_compositions.rb', line 270

def initialize(qty=nil, unit=nil)
  puts "ParseDose.new from #{qty.inspect} #{unit.inspect} #{unit.inspect}" if VERBOSE_MESSAGES
  if qty and (qty.is_a?(String) || qty.is_a?(Parslet::Slice))
    string = qty.to_s.gsub("'", '')
    if string.index('-') and (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

Instance Attribute Details

#qtyObject (readonly)

Returns the value of attribute qty.



268
269
270
# File 'lib/oddb2xml/parslet_compositions.rb', line 268

def qty
  @qty
end

#qty_rangeObject (readonly)

Returns the value of attribute qty_range.



268
269
270
# File 'lib/oddb2xml/parslet_compositions.rb', line 268

def qty_range
  @qty_range
end

#unitObject

Returns the value of attribute unit.



269
270
271
# File 'lib/oddb2xml/parslet_compositions.rb', line 269

def unit
  @unit
end

Instance Method Details

#evalObject



288
289
290
# File 'lib/oddb2xml/parslet_compositions.rb', line 288

def eval
  self
end

#to_sObject



291
292
293
294
295
296
# File 'lib/oddb2xml/parslet_compositions.rb', line 291

def to_s
  return @unit unless @qty or @qty_range
  res = "#{@qty}#{@qty_range}"
  res = "#{res} #{@unit}" if @unit
  res
end