Class: Semi::Variables::Integer

Inherits:
Base
  • Object
show all
Defined in:
lib/semi/variables/integer.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#!=, #!~, #&, #<=>, #==, #===, #=~, #^, #eql?, #equal?, #initialize, #set, #to_s, #value, #|

Constructor Details

This class inherits a constructor from Semi::Variables::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



30
31
32
# File 'lib/semi/variables/integer.rb', line 30

def method_missing(m, *args, &block)
  @value.to_i.send(m, *args, &block)
end

Class Method Details

.validate(value) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/semi/variables/integer.rb', line 21

def self.validate(value)
  if value.class == Fixnum
    return true
  elsif value.class == Semi::Variables::Integer and value.to_s =~ /^\d+$/
    return true
  end
  false
end

Instance Method Details

#validateObject

def set(val)

# test to see if the value is a common true value
if value =~ /true|yes|enable/i
  @value = true
elsif value =~ /false|no|disable/i
  @value = false
else
  raise Semi::VariableError, "#{val} trying to be set as a boolean"
end

end



17
18
19
# File 'lib/semi/variables/integer.rb', line 17

def validate
  self.validate(@value)
end