Class: NoSE::Fields::BooleanField
- Defined in:
- lib/nose/model/fields.rb
Overview
Field holding a boolean value
Constant Summary collapse
- TYPE =
Since Ruby has no boolean type, we use Object but all values will be either false or true
Object
Instance Attribute Summary
Attributes inherited from Field
#name, #parent, #primary_key, #size
Class Method Summary collapse
-
.value_from_string(string) ⇒ Boolean
Check for strings true or false otherwise assume integer.
Instance Method Summary collapse
-
#initialize(name, **options) ⇒ BooleanField
constructor
A new instance of BooleanField.
-
#random_value ⇒ Boolean
Randomly true or false.
Methods inherited from Field
#*, #==, #cardinality, #hash, #id, #to_color, #to_s
Methods included from Supertype
Constructor Details
#initialize(name, **options) ⇒ BooleanField
Returns a new instance of BooleanField.
143 144 145 146 |
# File 'lib/nose/model/fields.rb', line 143 def initialize(name, **) super(name, 1, **) @cardinality = 2 end |
Class Method Details
.value_from_string(string) ⇒ Boolean
Check for strings true or false otherwise assume integer
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/nose/model/fields.rb', line 150 def self.value_from_string(string) string = string.downcase if string[0] == 't' return true elsif string[0] == 'f' return false else [false, true][string.to_i] end end |
Instance Method Details
#random_value ⇒ Boolean
Randomly true or false
163 164 165 |
# File 'lib/nose/model/fields.rb', line 163 def random_value [false, true][rand(2)] end |