Class: Bigqueryid::Coercer

Inherits:
Object
  • Object
show all
Defined in:
lib/bigqueryid/coercer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(schema, coercer = Coercible::Coercer.new) ⇒ Coercer

Returns a new instance of Coercer.



5
6
7
8
# File 'lib/bigqueryid/coercer.rb', line 5

def initialize(schema, coercer = Coercible::Coercer.new)
  @coercer = coercer
  @schema  = schema
end

Instance Attribute Details

#coercerObject (readonly)

Returns the value of attribute coercer.



3
4
5
# File 'lib/bigqueryid/coercer.rb', line 3

def coercer
  @coercer
end

#schemaObject (readonly)

Returns the value of attribute schema.



3
4
5
# File 'lib/bigqueryid/coercer.rb', line 3

def schema
  @schema
end

Instance Method Details

#coerce(name, value) ⇒ Object



10
11
12
13
14
# File 'lib/bigqueryid/coercer.rb', line 10

def coerce(name, value)
  return value if value.nil? || !has_type?(name)

  coerce_by_type(value, schema[name.to_s][:type])
end