Class: Hasta::SortedDataSource

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

Overview

Decorator for a data source that yields the contents in sorted order

Instance Method Summary collapse

Constructor Details

#initialize(data_source) ⇒ SortedDataSource

Returns a new instance of SortedDataSource.



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

def initialize(data_source)
  @data_source = data_source
end

Instance Method Details

#each_lineObject



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

def each_line
  return enum_for(:each_line) unless block_given?

  sorted_lines.each do |line|
    yield line
  end
end

#nameObject



10
11
12
# File 'lib/hasta/sorted_data_source.rb', line 10

def name
  data_source.name
end

#to_sObject



22
23
24
# File 'lib/hasta/sorted_data_source.rb', line 22

def to_s
  "#<#{self.class.name}:#{name} size=#{lines.count} lines>"
end