Class: Semi::Variables::Boolean

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize, #to_s

Constructor Details

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

Class Method Details

.validate(value) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/semi/variables/boolean.rb', line 22

def self.validate(value)
  real_value = nil

  # test to see if the value is a common true value
  if value =~ /true|yes|enable/i
    real_value = true
  elsif value =~ /false|no|disable/i
    real_value = false
  end

  if !!real_value == real_value
    return true
  end
  false
end

Instance Method Details

#set(val) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/semi/variables/boolean.rb', line 7

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

#validateObject



18
19
20
# File 'lib/semi/variables/boolean.rb', line 18

def validate
  self.validate(@value)
end