class CsvToSqlite::SQL::Column

Public Class Methods

new(csv_table: @csv_table = csv_table) click to toggle source
# File lib/sql/column.rb, line 5
def initialize csv_table:
  @csv_table = csv_table
end

Public Instance Methods

boolean?() click to toggle source
# File lib/sql/column.rb, line 42
def boolean?
  match_cases = @data.map do |value|
    return true if value == 't' or value == 'f' or value == 'true' or value == 'false'
    return false
  end
  match_cases.all { |value| value == true }
end
date?() click to toggle source
# File lib/sql/column.rb, line 50
def date?
  match_cases = @data.map do |value|
    begin
      Date.parse value
      return true unless value.include? ":"
      return false
    rescue ArgumentError
      return false
    end
  end
  match_cases.all { |value| value == true }
end
datetime?() click to toggle source
# File lib/sql/column.rb, line 63
def datetime?
  match_cases = @data.map do |value|
    begin
      DateTime.parse value
      return true if value.include? ":"
      return false
    rescue ArgumentError
      return false
    end
  end
  match_cases.all { |value| value == true }
end
float?() click to toggle source
# File lib/sql/column.rb, line 38
def float?
  meta_comparing :Float
end
int?() click to toggle source
# File lib/sql/column.rb, line 34
def int?
  meta_comparing :Integer
end
meta_comparing(type) click to toggle source
# File lib/sql/column.rb, line 76
def meta_comparing type
  match_cases = @data.map do |value|
    begin
      method = Kernel.method(type)
      method.call value
      return true
    rescue ArgumentError
      return false
    end
  end
  match_cases.all { |value| value == true }
end
null?() click to toggle source
# File lib/sql/column.rb, line 29
def null?
  match_cases = @data.map { |value| value == nil }
  match_cases.any? { |value| value == true }
end
sql_for(column) click to toggle source
# File lib/sql/column.rb, line 9
def sql_for column
  @data = @csv_table[column][0..2]
  if null?
    type = "TEXT DEFAULT NULL"
  elsif int?
    type = "INTEGER"
  elsif float?
    type = "FLOAT"
  elsif boolean?
    type = "BOOLEAN"
  elsif datetime?
    type = "DATETIME"
  elsif date?
    type = "DATE"
  else
    type = "TEXT"
  end
  "#{column} #{type},"
end