Class: Arrow::MapArrayBuilder
- Inherits:
-
Object
- Object
- Arrow::MapArrayBuilder
- Defined in:
- lib/arrow/map-array-builder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #append_value(*args) ⇒ Object
- #append_value_raw ⇒ Object
- #append_values(values, is_valids = nil) ⇒ Object
- #append_values_raw ⇒ Object
Class Method Details
.build(data_type, values) ⇒ Object
21 22 23 24 |
# File 'lib/arrow/map-array-builder.rb', line 21 def build(data_type, values) builder = new(data_type) builder.build(values) end |
Instance Method Details
#append_value ⇒ Object #append_value(value) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/arrow/map-array-builder.rb', line 45 def append_value(*args) n_args = args.size case n_args when 0 append_value_raw when 1 value = args[0] case value when nil append_null else unless value.respond_to?(:each) = "map value must be nil, Hash or Object that has #each: #{value.inspect}" raise ArgumentError, end append_value_raw @key_builder ||= key_builder @item_builder ||= item_builder case value when Hash keys = value.keys values = value.values else keys = [] values = [] value.each do |key, item| keys << key values << item end end @key_builder.append(*keys) @item_builder.append(*values) end else = "wrong number of arguments (given #{n_args}, expected 0..1)" raise ArgumentError, end end |
#append_value_raw ⇒ Object
27 |
# File 'lib/arrow/map-array-builder.rb', line 27 alias_method :append_value_raw, :append_value |
#append_values(values, is_valids = nil) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/arrow/map-array-builder.rb', line 87 def append_values(values, is_valids=nil) value = values[0] case value when Integer append_values_raw(values, is_valids) else if is_valids is_valids.each_with_index do |is_valid, i| if is_valid append_value(values[i]) else append_null end end else values.each do |value| append_value(value) end end end end |
#append_values_raw ⇒ Object
85 |
# File 'lib/arrow/map-array-builder.rb', line 85 alias_method :append_values_raw, :append_values |