Sha256: 06af1b8a68b35099cb179f65ef6bd261e437146c2662bf468a028634603a367b

Contents?: true

Size: 771 Bytes

Versions: 1

Compression:

Stored size: 771 Bytes

Contents

module IMW

  class Uri

    attr_reader :scheme, :format

    @@schemes = {
      %r{^hdfs:} => 'Hdfs',
      %r{^s3:}   => 'S3',
    }

    @@formats = {
      %r{.csv$}   => 'Csv',
      %r{.tsv$}   => 'Tsv',
      %r{.json$}  => 'Json',
      %r{.ya?ml$} => 'Yaml',
    }

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

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

    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

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
imw-0.3.0 lib/imw/uri.rb