Class: NoSE::Fields::BooleanField

Inherits:
Field show all
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

Instance Method Summary collapse

Methods inherited from Field

#*, #==, #cardinality, #hash, #id, #to_color, #to_s

Methods included from Supertype

included

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, **options)
  super(name, 1, **options)
  @cardinality = 2
end

Class Method Details

.value_from_string(string) ⇒ Boolean

Check for strings true or false otherwise assume integer

Returns:

  • (Boolean)


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_valueBoolean

Randomly true or false

Returns:

  • (Boolean)


163
164
165
# File 'lib/nose/model/fields.rb', line 163

def random_value
  [false, true][rand(2)]
end