Class: Embulk::Column

Inherits:
Struct
  • Object
show all
Defined in:
lib/embulk/column.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Column

Returns a new instance of Column.



4
5
6
7
8
9
10
11
12
13
# File 'lib/embulk/column.rb', line 4

def initialize(*args)
  if args.length == 1 && args[0].is_a?(Hash)
    # initialize(hash)
    hash = args.first
    super(hash[:index], hash[:name], hash[:type], hash[:format])
  else
    # initialize(index, name, type, format)
    super(*args)
  end
end

Instance Attribute Details

#formatObject

Returns the value of attribute format

Returns:

  • (Object)

    the current value of format



3
4
5
# File 'lib/embulk/column.rb', line 3

def format
  @format
end

#indexObject

Returns the value of attribute index

Returns:

  • (Object)

    the current value of index



3
4
5
# File 'lib/embulk/column.rb', line 3

def index
  @index
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/embulk/column.rb', line 3

def name
  @name
end

#typeObject

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



3
4
5
# File 'lib/embulk/column.rb', line 3

def type
  @type
end

Class Method Details

.from_java(java_column) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/embulk/column.rb', line 23

def self.from_java(java_column)
  type = Type.from_java(java_column.getType)
  if type == :timestamp
    format = java_column.getType.getFormat
  else
    format = nil
  end

  Column.new(java_column.getIndex, java_column.getName, type, format)
end

Instance Method Details

#to_javaObject



34
35
36
37
38
39
40
# File 'lib/embulk/column.rb', line 34

def to_java
  if type == :timestamp && format
    Java::Column.new(index, name, Type.new_java_type(type).withFormat(format))
  else
    Java::Column.new(index, name, Type.new_java_type(type))
  end
end

#to_json(*args) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/embulk/column.rb', line 15

def to_json(*args)
  if type == :timestamp && format
    {"index"=>index, "name"=>name, "type"=>type, "format"=>format}.to_json(*args)
  else
    {"index"=>index, "name"=>name, "type"=>type}.to_json(*args)
  end
end