Class: BqFactory::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/bq_factory/attribute.rb

Constant Summary collapse

PERMIT_TYPES =
%i(STRING INTEGER FLOAT TIMESTAMP BOOLEAN RECORD).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type) ⇒ Attribute

Returns a new instance of Attribute.

Raises:

  • (ArgumentError.new)


8
9
10
11
12
13
# File 'lib/bq_factory/attribute.rb', line 8

def initialize(name, type)
  type = type.to_sym
  raise ArgumentError.new, "#{type} is not implemented" unless PERMIT_TYPES.include?(type)
  @name = name
  @type = type
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/bq_factory/attribute.rb', line 6

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/bq_factory/attribute.rb', line 6

def type
  @type
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/bq_factory/attribute.rb', line 5

def value
  @value
end

Instance Method Details

#to_sqlObject



15
16
17
# File 'lib/bq_factory/attribute.rb', line 15

def to_sql
  "#{cast_to_sql(value)} AS #{name}"
end