class Ittan::Column

Attributes

name[RW]
seed_file[RW]
text[RW]

Public Class Methods

new(column_text, seed_file) click to toggle source
# File lib/ittan/column.rb, line 9
def initialize(column_text, seed_file)
  @text = column_text
  @seed_file = seed_file
  @name = extract_column_name
end

Public Instance Methods

input_dummy_data() click to toggle source
# File lib/ittan/column.rb, line 15
def input_dummy_data
  input_file create_string_dummy    if @text.include?('t.string')
  input_file create_text_dummy      if @text.include?('t.text')
  input_file create_integer_dummy   if @text.include?('t.integer')
  input_file create_float_dummy     if @text.include?('t.float')
  input_file create_decimal_dummy   if @text.include?('t.decimal')
  input_file create_boolean_dummy   if @text.include?('t.boolean')
  input_file create_date_dummy      if @text.include?('t.date ')
  input_file create_time_dummy      if @text.include?('t.time')
  input_file create_datetime_dummy  if @text.include?('t.datetime')
end

Private Instance Methods

create_boolean_dummy() click to toggle source
# File lib/ittan/column.rb, line 92
def create_boolean_dummy
  Faker::Boolean.boolean
end
create_date_dummy() click to toggle source
# File lib/ittan/column.rb, line 80
def create_date_dummy
  "\"Faker::Date.between(Date.today, Date.today)\""
end
create_datetime_dummy() click to toggle source
# File lib/ittan/column.rb, line 88
def create_datetime_dummy
  "\"#{Faker::Time.between(DateTime.now, DateTime.now)}\""
end
create_decimal_dummy() click to toggle source
# File lib/ittan/column.rb, line 67
def create_decimal_dummy
  precision = extract_column_precision
  scale = extract_column_scale
  if scale.nil?
    integer_part = rand(1..precision - 1)
    decimal_part = precision - integer_part
  else
    decimal_part = scale
    integer_part = precision - decimal_part
  end
  Faker::Number.decimal(integer_part, decimal_part)
end
create_float_dummy() click to toggle source
# File lib/ittan/column.rb, line 61
def create_float_dummy
  limit = extract_column_limit
  limit_random = rand(1..limit)
  Faker::Number.decimal(limit_random)
end
create_integer_dummy() click to toggle source
# File lib/ittan/column.rb, line 55
def create_integer_dummy
  limit = extract_column_limit
  limit_random = rand(1..limit)
  Faker::Number.number(limit_random)
end
create_string_dummy() click to toggle source
# File lib/ittan/column.rb, line 45
def create_string_dummy
  limit = extract_column_limit
  limit_random = rand(1..limit)
  "\"#{Faker::Lorem.characters(limit_random)}\""
end
create_text_dummy() click to toggle source
# File lib/ittan/column.rb, line 51
def create_text_dummy
  "\"#{Faker::Lorem.sentence}\""
end
create_time_dummy() click to toggle source
# File lib/ittan/column.rb, line 84
def create_time_dummy
  "\"#{Time.now.to_time_of_day}\""
end
extract_column_limit() click to toggle source
# File lib/ittan/column.rb, line 33
def extract_column_limit
  @text.match("(limit: )[0-9]*") { |match_data| match_data[0].delete("^0-9").to_i }
end
extract_column_name() click to toggle source
# File lib/ittan/column.rb, line 29
def extract_column_name
  @text.match("\"[a-zA-Z0-9_]*\"")[0].delete("\"")
end
extract_column_precision() click to toggle source
# File lib/ittan/column.rb, line 37
def extract_column_precision
  @text.match("(precision: )[0-9]*") { |match_data| match_data[0].delete("^0-9").to_i }
end
extract_column_scale() click to toggle source
# File lib/ittan/column.rb, line 41
def extract_column_scale
  @text.match("(scale: )[0-9]*") { |match_data| match_data[0].delete("^0-9").to_i }
end
input_file(dummy_data) click to toggle source
# File lib/ittan/column.rb, line 96
def input_file(dummy_data)
  @seed_file.puts "#{@name}: #{dummy_data},"
end