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

#!=, #!~, #&, #<=>, #==, #===, #=~, #^, #eql?, #equal?, #initialize, #method_missing, #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 in the class Semi::Variables::Base

Class Method Details

.validate(value) ⇒ Object



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

def self.validate(value)
  real_value = nil

  # If Semi::Variables::Boolean, then get the string representation
  if value.class == Semi::Variables::Boolean
    value = value.to_s
  end

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

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

Instance Method Details

#EnableDisableObject



95
96
97
# File 'lib/semi/variables/boolean.rb', line 95

def EnableDisable
  enabledisable.capitalize
end

#ENABLEDISABLEObject



91
92
93
# File 'lib/semi/variables/boolean.rb', line 91

def ENABLEDISABLE
  enabledisable.upcase
end

#enabledisableObject



83
84
85
86
87
88
89
# File 'lib/semi/variables/boolean.rb', line 83

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

#onoffObject



49
50
51
52
53
54
55
# File 'lib/semi/variables/boolean.rb', line 49

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

#ONOFFObject



57
58
59
# File 'lib/semi/variables/boolean.rb', line 57

def ONOFF
  onoff.upcase
end

#OnOffObject



61
62
63
# File 'lib/semi/variables/boolean.rb', line 61

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



112
113
114
# File 'lib/semi/variables/boolean.rb', line 112

def TrueFalse
  truefalse.capitalize
end

#TRUEFALSEObject



108
109
110
# File 'lib/semi/variables/boolean.rb', line 108

def TRUEFALSE
  truefalse.upcase
end

#truefalseObject



100
101
102
103
104
105
106
# File 'lib/semi/variables/boolean.rb', line 100

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



66
67
68
69
70
71
72
# File 'lib/semi/variables/boolean.rb', line 66

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

#YESNOObject



74
75
76
# File 'lib/semi/variables/boolean.rb', line 74

def YESNO
  yesno.upcase
end

#YesNoObject



78
79
80
# File 'lib/semi/variables/boolean.rb', line 78

def YesNo
  yesno.capitalize
end