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.
155 156 157 158 |
# File 'lib/nose/model/fields.rb', line 155 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
162 163 164 165 166 167 168 169 170 171 |
# File 'lib/nose/model/fields.rb', line 162 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
175 176 177 |
# File 'lib/nose/model/fields.rb', line 175 def random_value [false, true][rand(2)] end |