class StructuredNoise::Generator::TypeGenerator

Public Class Methods

new(field) click to toggle source
# File lib/structured_noise/generator.rb, line 71
def initialize(field)
  @field = field
end

Public Instance Methods

generate_int() click to toggle source
# File lib/structured_noise/generator.rb, line 99
def generate_int
  (0..100).to_a.sample
end
generate_long() click to toggle source
# File lib/structured_noise/generator.rb, line 97
def generate_long; generate_int; end
generate_string() click to toggle source
# File lib/structured_noise/generator.rb, line 103
def generate_string
  letters = ('a'..'z').to_a
  generate_int.times.map{ letters.sample }.join
end
generate_union(field) click to toggle source
# File lib/structured_noise/generator.rb, line 108
def generate_union(field)
  selected_type = field.type.schemas.sample
  generate_value(selected_type)
end
generate_value(type = @field.type) click to toggle source
# File lib/structured_noise/generator.rb, line 76
def generate_value(type = @field.type)
  case type.type_sym
  when :null;    nil
  when :boolean; generate_boolean
  when :string;  generate_string
  when :int;     generate_int
  when :long;    generate_long
  when :float;   generate_float
  when :double;  generate_double
  when :bytes;   generate_bytes
  when :fixed;   generate_fixed
  when :enum;    generate_enum
  when :array;   generate_array
  when :map;     generate_map
  when :union;   generate_union(@field)
  #when :record, :error, :request;
  else
    raise Avro::AvroError.new("Unknown type: #{writers_schema.type}")
  end
end