Class: LiquidStream::Streams

Inherits:
Stream
  • Object
show all
Defined in:
lib/liquid_stream/streams.rb

Instance Attribute Summary

Attributes inherited from Stream

#source, #stream_context

Instance Method Summary collapse

Methods inherited from Stream

#before_method, stream

Constructor Details

#initialize(source = nil, stream_context = {}) ⇒ Streams

Returns a new instance of Streams.



8
9
10
11
# File 'lib/liquid_stream/streams.rb', line 8

def initialize(source=nil, stream_context={})
  @source = source_from(source)
  @stream_context = stream_context
end

Instance Method Details

#each(&block) ⇒ Object



27
28
29
# File 'lib/liquid_stream/streams.rb', line 27

def each(&block)
  to_a.each(&block)
end

#firstObject



13
14
15
# File 'lib/liquid_stream/streams.rb', line 13

def first
  @first ||= singleton_class.new(@source.first)
end

#lastObject



17
18
19
# File 'lib/liquid_stream/streams.rb', line 17

def last
  @last ||= singleton_class.new(@source.last)
end

#to_aObject



21
22
23
24
25
# File 'lib/liquid_stream/streams.rb', line 21

def to_a
  @source.map do |object|
    singleton_class.new(object)
  end
end