Class: IMW::Uri

Inherits:
Object
  • Object
show all
Defined in:
lib/imw/uri.rb

Constant Summary collapse

@@schemes =
{
  %r{^hdfs:} => 'Hdfs',
  %r{^s3:}   => 'S3',
}
@@formats =
{
  %r{.csv$}   => 'Csv',
  %r{.tsv$}   => 'Tsv',
  %r{.json$}  => 'Json',
  %r{.ya?ml$} => 'Yaml',
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Uri

Returns a new instance of Uri.



19
20
21
22
# File 'lib/imw/uri.rb', line 19

def initialize uri
  @scheme = lookup_scheme(uri)
  @format = lookup_format(uri)
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



5
6
7
# File 'lib/imw/uri.rb', line 5

def format
  @format
end

#schemeObject (readonly)

Returns the value of attribute scheme.



5
6
7
# File 'lib/imw/uri.rb', line 5

def scheme
  @scheme
end

Instance Method Details

#lookup_format(uri) ⇒ Object

Raises:



32
33
34
35
36
37
38
# File 'lib/imw/uri.rb', line 32

def lookup_format uri
  @@formats.keys.each do |key|
    next unless uri =~ key
    return @@formats[key]
  end
  raise InvalidFormatError.new("#{File.extname(uri)} is not currently supported")
end

#lookup_scheme(uri) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/imw/uri.rb', line 24

def lookup_scheme uri
  @@schemes.keys.each do |key|
    next unless uri =~ key
    return @@schemes[key]
  end
  'Local'
end