Class: Masticate::Datify
Overview
convert date columns to numerics
Instance Attribute Summary
Attributes inherited from Base
#csv_options, #filename, #input, #input_count, #output, #output_count
Instance Method Summary collapse
Methods inherited from Base
#emit, #execute, #get, #initialize, #standard_options, #with_input
Constructor Details
This class inherits a constructor from Masticate::Base
Instance Method Details
#configure(opts) ⇒ Object
4 5 6 7 8 |
# File 'lib/masticate/datify.rb', line 4 def configure(opts) (opts) @field = opts[:field] or raise "missing field to datify" @format = opts[:format] or raise "strptime format required for parsing timestamps" end |
#crunch(row) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/masticate/datify.rb', line 14 def crunch(row) if !@index if @field.is_a?(Fixnum) || @field =~ /^\d+/ @index = @field.to_i else @index = row.index(@field) or raise "Unable to find column '#{@field}'" end elsif row row[@index] = DateTime.strptime(row[@index], @format).to_time.to_i rescue nil end row end |
#datify(opts) ⇒ Object
10 11 12 |
# File 'lib/masticate/datify.rb', line 10 def datify(opts) execute(opts) end |