Class: Arrow::TableLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/arrow/table-loader.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, options = {}) ⇒ TableLoader

Returns a new instance of TableLoader.



28
29
30
31
32
33
# File 'lib/arrow/table-loader.rb', line 28

def initialize(input, options={})
  input = input.to_path if input.respond_to?(:to_path)
  @input = input
  @options = options
  fill_options
end

Class Method Details

.load(input, options = {}) ⇒ Object



23
24
25
# File 'lib/arrow/table-loader.rb', line 23

def load(input, options={})
  new(input, options).load
end

Instance Method Details

#loadObject

Raises:

  • (ArgumentError)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/arrow/table-loader.rb', line 35

def load
  if @input.is_a?(URI)
    custom_load_method_candidates = []
    if @input.scheme
      custom_load_method_candidates << "load_from_uri_#{@input.scheme}"
    end
    custom_load_method_candidates << "load_from_uri"
  elsif @input.is_a?(String) and ::File.directory?(@input)
    custom_load_method_candidates = ["load_from_directory"]
  else
    custom_load_method_candidates = ["load_from_file"]
  end
  custom_load_method_candidates.each do |custom_load_method|
    next unless respond_to?(custom_load_method, true)
    return __send__(custom_load_method)
  end
  available_schemes = []
  (methods(true) | private_methods(true)).each do |name|
    match_data = /\Aload_from_/.match(name.to_s)
    if match_data
      available_schemes << match_data.post_match
    end
  end
  message = "Arrow::Table load source must be one of ["
  message << available_schemes.join(", ")
  message << "]: #{@input.inspect}"
  raise ArgumentError, message
end