Sha256: d33ca9d59722300e430734986d16042f081f44c22beb91eb883aa0f3323ba5bd

Contents?: true

Size: 663 Bytes

Versions: 7

Compression:

Stored size: 663 Bytes

Contents

# convert date columns to numerics

class Masticate::Datify < Masticate::Base
  def configure(opts)
    standard_options(opts)
    @field = opts[:field] or raise "missing field to datify"
    @format = opts[:format] or raise "strptime format required for parsing timestamps"
  end

  def datify(opts)
    execute(opts)
  end

  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
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
masticate-0.6.2 lib/masticate/datify.rb
masticate-0.6.1 lib/masticate/datify.rb
masticate-0.6.0 lib/masticate/datify.rb
masticate-0.5.1 lib/masticate/datify.rb
masticate-0.5.0 lib/masticate/datify.rb
masticate-0.4.2 lib/masticate/datify.rb
masticate-0.4.1 lib/masticate/datify.rb