Class: ParseDose
- Inherits:
-
Object
- Object
- ParseDose
- Defined in:
- lib/oddb2xml/parslet_compositions.rb
Instance Attribute Summary collapse
-
#qty ⇒ Object
readonly
Returns the value of attribute qty.
-
#qty_range ⇒ Object
readonly
Returns the value of attribute qty_range.
-
#unit ⇒ Object
Returns the value of attribute unit.
Instance Method Summary collapse
- #eval ⇒ Object
-
#initialize(qty = nil, unit = nil) ⇒ ParseDose
constructor
A new instance of ParseDose.
- #to_s ⇒ Object
Constructor Details
#initialize(qty = nil, unit = nil) ⇒ ParseDose
Returns a new instance of ParseDose.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 |
# 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 |
Instance Attribute Details
#qty ⇒ Object (readonly)
Returns the value of attribute qty.
297 298 299 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 297 def qty @qty end |
#qty_range ⇒ Object (readonly)
Returns the value of attribute qty_range.
297 298 299 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 297 def qty_range @qty_range end |
#unit ⇒ Object
Returns the value of attribute unit.
298 299 300 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 298 def unit @unit end |
Instance Method Details
#eval ⇒ Object
318 319 320 |
# File 'lib/oddb2xml/parslet_compositions.rb', line 318 def eval self end |
#to_s ⇒ Object
322 323 324 325 326 327 |
# 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 |