class Relationize::Relationizer
Relationizer
Base Class
Public Class Methods
new(tuples, schema, name)
click to toggle source
@param [Array] tuples: Expected to two dimentional Array. For example ‘[[1, 2], [3, 4]]` @param [Hash] schema: For example `{ id: :integer, amount: :integer}` @param [String] name: Relation name
# File lib/relationize/relationizer.rb, line 17 def initialize(tuples, schema, name) unless tuples.all? { |o| o.is_a?(Array) } raise InvalidElementError.new("Element should be Array") end unless tuples.map(&:length).all? { |length| length == schema.length } raise InvalidSchemaError.new("Tuple size is expected #{schema.length}.") end @tuples, @name, @columns, @types = tuples, name, schema.keys, schema.values end
Private Instance Methods
identifer_quote(w)
click to toggle source
# File lib/relationize/relationizer.rb, line 31 def identifer_quote(w) %Q{"#{w.to_s.gsub(/"/, '""')}"} end
oriented_types()
click to toggle source
# File lib/relationize/relationizer.rb, line 35 def oriented_types @tuples.transpose.zip(@types).map do |(values, type)| next type.to_s.upcase if type values.map(&:class).uniq. map(&self.class::DEFAULT_TYPES).compact.uniq. tap { |types| raise ReasonlessTypeError.new("Many candidate: #{types.join(', ')}") unless types.one? }. tap { |types| raise ReasonlessTypeError.new("Candidate nothing") if types.empty? }. first.to_s.upcase end end