Class: VectorEmbed::Maker::Boolean

Inherits:
VectorEmbed::Maker show all
Defined in:
lib/vector_embed/maker/boolean.rb

Instance Attribute Summary

Attributes inherited from VectorEmbed::Maker

#cardinality, #k, #options, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VectorEmbed::Maker

#initialize, pick

Constructor Details

This class inherits a constructor from VectorEmbed::Maker

Class Method Details

.want?(v, parent) ⇒ Boolean

Returns:



7
8
9
10
11
12
13
14
# File 'lib/vector_embed/maker/boolean.rb', line 7

def want?(v, parent)
  case v
  when TrueClass, FalseClass, TRUE, FALSE, T, F
    true
  else
    false
  end
end

Instance Method Details

#pairs(v) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/vector_embed/maker/boolean.rb', line 28

def pairs(v)
  case v
  when TrueClass, TRUE, T, 1, '1'
    [ [ parent.index([k, 'true']), 1 ] ]
  when FalseClass, FALSE, F, 0, '0'
    [ [ parent.index([k, 'false']), 1 ] ]
  when NilClass, NULL, SLASH_N, BLANK
    [ [ parent.index([k, 'null']), 1 ] ]
  else
    raise ArgumentError, "Can't embed #{v.inspect} in boolean feature #{k.inspect}"
  end
end

#value(v) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/vector_embed/maker/boolean.rb', line 17

def value(v)
  case v
  when TrueClass, TRUE, T
    1
  when FalseClass, FALSE, F
    0
  else
    raise "Can't embed #{v.inspect} in boolean feature #{k.inspect}"
  end
end