Class: Firuta::Base

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

Direct Known Subclasses

Commands::Map

Constant Summary collapse

COMMANDS =
[
  [:filter,   Commands::Filter],
  [:map,      Commands::Map],
  [:sort,     Commands::Sort],
  [:reduce,   Commands::Reduce],
  [:paginate, Commands::Paginate],
  [:uniq,     Commands::Uniq],
  [:find,     Commands::Find]
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(collection = nil) ⇒ Base

Returns a new instance of Base.



16
17
18
19
20
# File 'lib/firuta.rb', line 16

def initialize(collection = nil)
  @commands = []
  @collection = collection
  @terminal_command_added = false
end

Instance Method Details

#apply(collection = nil) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/firuta.rb', line 42

def apply(collection = nil)
  result = collection || @collection
  @commands.each do |command|
    result = command.apply_to(result)
  end
  result
end