Class: VectorEmbed::Maker::Date
Constant Summary
collapse
- BASE =
::Date.new(2000,1,1)
- BLANK =
/\A\s*\z/
Instance Attribute Summary
#k, #parent
Class Method Summary
collapse
Instance Method Summary
collapse
#initialize, #pairs, pick
Class Method Details
.want?(v, parent) ⇒ Boolean
8
9
10
|
# File 'lib/vector_embed/maker/date.rb', line 8
def want?(v, parent)
v.is_a?(::Date)
end
|
Instance Method Details
#value(v) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/vector_embed/maker/date.rb', line 16
def value(v)
date = case v
when ::String
if v !~ BLANK
::Date.parse v
end
when ::Date
v
else
raise "Can't embed #{v.inspect} in date feature #{k.inspect}"
end
if date
num = (date - BASE).to_i
if num.nonzero?
num
end
end
end
|