Class: Hasta::CombinedDataSource

Inherits:
Object
  • Object
show all
Defined in:
lib/hasta/combined_data_source.rb

Overview

Combines multiple data sources so they can be iterated over continuously

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sources, name = nil) ⇒ CombinedDataSource

Returns a new instance of CombinedDataSource.



8
9
10
11
# File 'lib/hasta/combined_data_source.rb', line 8

def initialize(sources, name = nil)
  @sources = sources
  @name = name || sources.map(&:name).compact.join(', ')
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/hasta/combined_data_source.rb', line 6

def name
  @name
end

Instance Method Details

#each_lineObject



13
14
15
16
17
18
19
20
21
# File 'lib/hasta/combined_data_source.rb', line 13

def each_line
  return enum_for(:each_line) unless block_given?

  sources.each do |source|
    source.each_line do |line|
      yield line
    end
  end
end

#to_aObject



23
24
25
# File 'lib/hasta/combined_data_source.rb', line 23

def to_a
  each_line.to_a
end

#to_sObject



27
28
29
# File 'lib/hasta/combined_data_source.rb', line 27

def to_s
  "#<#{self.class.name}:#{name}>"
end