Class: Arrow::DataType
- Inherits:
-
Object
- Object
- Arrow::DataType
- Defined in:
- lib/arrow/data-type.rb
Class Method Summary collapse
-
.resolve(data_type) ⇒ Object
Creates a new suitable DataType.
- .sub_types ⇒ Object
- .try_convert(value) ⇒ Object
Instance Method Summary collapse
Class Method Details
.resolve(data_type) ⇒ Arrow::DataType .resolve(name) ⇒ Object .resolve(name_with_arguments) ⇒ Object .resolve(description) ⇒ Object
Creates a new suitable Arrow::DataType.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/arrow/data-type.rb', line 83 def resolve(data_type) case data_type when DataType data_type when String, Symbol resolve_class(data_type).new when ::Array type, *arguments = data_type resolve_class(type).new(*arguments) when Hash type = nil description = {} data_type.each do |key, value| key = key.to_sym case key when :type type = value else description[key] = value end end if type.nil? = "data type description must have :type value: #{data_type.inspect}" raise ArgumentError, end data_type_class = resolve_class(type) if description.empty? data_type_class.new else data_type_class.new(description) end else = "data type must be " + "Arrow::DataType, String, Symbol, [String, ...], [Symbol, ...] " + "{type: String, ...} or {type: Symbol, ...}: #{data_type.inspect}" raise ArgumentError, end end |
.sub_types ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/arrow/data-type.rb', line 124 def sub_types types = {} gtype.children.each do |child| sub_type = child.to_class types[sub_type] = true sub_type.sub_types.each do |sub_sub_type| types[sub_sub_type] = true end end types.keys end |
.try_convert(value) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/arrow/data-type.rb', line 136 def try_convert(value) begin resolve(value) rescue ArgumentError nil end end |
Instance Method Details
#build_array(values) ⇒ Object
181 182 183 184 185 186 187 |
# File 'lib/arrow/data-type.rb', line 181 def build_array(values) base_name = self.class.name.gsub(/DataType\z/, "") builder_class = self.class.const_get("#{base_name}ArrayBuilder") args = [values] args.unshift(self) unless builder_class.buildable?(args) builder_class.build(*args) end |