Sha256: 131b15130ae9e71a90db2077f3eb4afe04ddf59e5be7256724e01016d1f6fc3a

Contents?: true

Size: 961 Bytes

Versions: 1

Compression:

Stored size: 961 Bytes

Contents

require 'date'

module Parse
  module Db
    class Import

      DATE_CONVENTIONS = [ /At$/, /date$/, /^last/ ]

      def map_data_types(record)
        #Convert arrays to strings, since we're not supporting them yet.
        record.each { |k, v| record[k] = v.join(', ') if v.is_a? Array }
        #Convert epoch to datetime
        record.each { |k, v| record[k] =  DateTime.strptime(v.to_s, "%Q") if is_date_by_naming_convention(k) }
      end

      def is_date_by_naming_convention column_name
        DATE_CONVENTIONS.any? { |regx| column_name =~ regx }
      end

      def klass_from_file(file)
        class_name = File.basename(File.dirname(file))
        get_class(class_name)
      end

      def process_parse_file(file, &block)
        IO.foreach(file) do |record|
          record = JSON.parse(record)
          record = map_data_types(record)
          next if record["delete"]
          yield(record)
        end
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parse-db-import-0.0.2 lib/parse/db/import/utils.rb