Class: Abroad::Extractors::Extractor

Inherits:
Object
  • Object
show all
Defined in:
lib/abroad/extractors/extractor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Extractor

Returns a new instance of Extractor.


31
32
33
# File 'lib/abroad/extractors/extractor.rb', line 31

def initialize(stream)
  @stream = stream
end

Instance Attribute Details

#streamObject (readonly)

Returns the value of attribute stream


7
8
9
# File 'lib/abroad/extractors/extractor.rb', line 7

def stream
  @stream
end

Class Method Details

.from_stream(stream) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/abroad/extractors/extractor.rb', line 10

def from_stream(stream)
  extractor = new(stream)

  if block_given?
    yield(extractor).tap do
      extractor.close
    end
  else
    extractor
  end
end

.from_string(string, &block) ⇒ Object


22
23
24
# File 'lib/abroad/extractors/extractor.rb', line 22

def from_string(string, &block)
  from_stream(StringIO.new(string), &block)
end

.open(file, mode = 'r', &block) ⇒ Object


26
27
28
# File 'lib/abroad/extractors/extractor.rb', line 26

def open(file, mode = 'r', &block)
  from_stream(File.open(file, mode), &block)
end

Instance Method Details

#closeObject


40
41
42
# File 'lib/abroad/extractors/extractor.rb', line 40

def close
  stream.close
end

#extract_each(options = {}) ⇒ Object

Raises:

  • (NotImplementedError)

35
36
37
38
# File 'lib/abroad/extractors/extractor.rb', line 35

def extract_each(options = {})
  raise NotImplementedError,
    'expected to be implemented in derived classes'
end