Class: Birddog::NumericExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/birddog/numeric_expression.rb

Instance Method Summary collapse

Constructor Details

#initialize(value, type) ⇒ NumericExpression

Returns a new instance of NumericExpression.



5
6
7
8
9
10
11
# File 'lib/birddog/numeric_expression.rb', line 5

def initialize(value, type)
  value.gsub!(/\s/, '')
  parts = value.scan(/(?:[=<>~]+|(?:-?\d|\.)+)/)[0,2]

  @value = Float(parts.last)
  @value = @value.to_i if type == :integer
end

Instance Method Details

#to_fObject



17
18
19
# File 'lib/birddog/numeric_expression.rb', line 17

def to_f
  @value.to_f
end

#to_iObject



13
14
15
# File 'lib/birddog/numeric_expression.rb', line 13

def to_i
  @value.to_i
end

#to_sObject



21
22
23
# File 'lib/birddog/numeric_expression.rb', line 21

def to_s
  @value.to_s
end