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, #value

Constructor Details

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

Class Method Details

.validate(value) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/semi/variables/boolean.rb', line 27

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

#EnableDisableObject



89
90
91
# File 'lib/semi/variables/boolean.rb', line 89

def EnableDisable
  enabledisable.capitalize
end

#ENABLEDISABLEObject



85
86
87
# File 'lib/semi/variables/boolean.rb', line 85

def ENABLEDISABLE
  enabledisable.upcase
end

#enabledisableObject



77
78
79
80
81
82
83
# File 'lib/semi/variables/boolean.rb', line 77

def enabledisable
  if @value
    'enable'
  else
    'disable'
  end
end

#onoffObject



43
44
45
46
47
48
49
# File 'lib/semi/variables/boolean.rb', line 43

def onoff
  if @value
    'on'
  else
    'off'
  end
end

#ONOFFObject



51
52
53
# File 'lib/semi/variables/boolean.rb', line 51

def ONOFF
  onoff.upcase
end

#OnOffObject



55
56
57
# File 'lib/semi/variables/boolean.rb', line 55

def OnOff
  onoff.capitalize
end

#set(val) ⇒ Object



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

def set(val)
  if val.instance_of? TrueClass
    @value = true
  elsif val.instance_of? FalseClass
    @value = false
  elsif val =~ /true|yes|on|enable/i
    # test to see if the value is a common true value
    @value = true
  elsif val =~ /false|no|off|disable/i
    # test to see if the value is a common false value
    @value = false
  else
    raise Semi::VariableError, "#{val} trying to be set as a boolean"
  end
end

#TrueFalseObject



106
107
108
# File 'lib/semi/variables/boolean.rb', line 106

def TrueFalse
  truefalse.capitalize
end

#TRUEFALSEObject



102
103
104
# File 'lib/semi/variables/boolean.rb', line 102

def TRUEFALSE
  truefalse.upcase
end

#truefalseObject



94
95
96
97
98
99
100
# File 'lib/semi/variables/boolean.rb', line 94

def truefalse
  if @value
    'true'
  else
    'false'
  end
end

#validateObject



23
24
25
# File 'lib/semi/variables/boolean.rb', line 23

def validate
  self.validate(@value)
end

#yesnoObject



60
61
62
63
64
65
66
# File 'lib/semi/variables/boolean.rb', line 60

def yesno()
  if @value
    'yes'
  else
    'no'
  end
end

#YESNOObject



68
69
70
# File 'lib/semi/variables/boolean.rb', line 68

def YESNO
  yesno.upcase
end

#YesNoObject



72
73
74
# File 'lib/semi/variables/boolean.rb', line 72

def YesNo
  yesno.capitalize
end