Class: Devinci::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/devinci/base.rb

Direct Known Subclasses

Bixi

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, options = {}) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/devinci/base.rb', line 7

def initialize(filename, options = {})
  @filename = filename
  @options = options
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/devinci/base.rb', line 5

def filename
  @filename
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/devinci/base.rb', line 5

def options
  @options
end

Instance Method Details

#downloaded_onObject



21
22
23
24
25
26
27
# File 'lib/devinci/base.rb', line 21

def downloaded_on
  match = filename.match(/(\d{4})-(\d{2})-(\d{2})..(\d{2}):(\d{2}):(\d{2})/)
  if match
    numbers = (1..6).map { |n| match[n].to_i }
    Time.utc(*numbers)
  end
end

#ioObject



12
13
14
15
16
17
18
19
# File 'lib/devinci/base.rb', line 12

def io
  @io ||= case @options[:compression]
  when :gzip
    Zlib::GzipReader.open(@filename)
  else
    File.open(@filename)
  end
end

#parseObject

Raises:

  • (NotImplementedError)


29
30
31
# File 'lib/devinci/base.rb', line 29

def parse
  raise NotImplementedError, "Each parser must define their own parse method"
end