Class: Elparser::SExpNumber

Inherits:
AbstractSExpAtom show all
Defined in:
lib/elparser.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractSExpAtom

#atom?

Methods inherited from AbstractSExp

#==, #atom?, #cons?, #list?, #visit

Constructor Details

#initialize(type, val) ⇒ SExpNumber

Returns a new instance of SExpNumber.



91
92
93
94
# File 'lib/elparser.rb', line 91

def initialize(type, val)
  @type = type
  @val = val
end

Class Method Details

.float(val) ⇒ Object



87
88
89
# File 'lib/elparser.rb', line 87

def self.float(val)
  SExpNumber.new(:FLOAT, val)
end

.int(val) ⇒ Object



84
85
86
# File 'lib/elparser.rb', line 84

def self.int(val)
  SExpNumber.new(:INTEGER, val)
end

Instance Method Details

#to_rubyObject



108
109
110
# File 'lib/elparser.rb', line 108

def to_ruby
  value
end

#to_sObject



105
106
107
# File 'lib/elparser.rb', line 105

def to_s
  @val
end

#valueObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/elparser.rb', line 95

def value
  case @type
  when :INTEGER
    @val.to_i
  when :FLOAT
    @val.to_f
  else
    raise "Unknown type #{@type}:#{@val}"
  end
end