Class: Webby::Filters::Cursor

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

Overview

Instances of this class handle processing a set of filters for a given renderer and page. Note: The instance is passed as the second argument to filters

that require two parameters and can be used to access 
information on the renderer, page, or filters being
processed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(renderer, page) ⇒ Cursor

Returns a new instance of Cursor.



42
43
44
45
46
47
# File 'lib/webby/filters.rb', line 42

def initialize(renderer, page)
  @renderer, @page = renderer, page
  @filters = Array(page.filter)
  @log = Logging::Logger[Webby::Renderer]
  @processed = 0
end

Instance Attribute Details

#filtersObject (readonly)

Returns the value of attribute filters.



41
42
43
# File 'lib/webby/filters.rb', line 41

def filters
  @filters
end

#pageObject (readonly)

Returns the value of attribute page.



41
42
43
# File 'lib/webby/filters.rb', line 41

def page
  @page
end

#rendererObject (readonly)

Returns the value of attribute renderer.



41
42
43
# File 'lib/webby/filters.rb', line 41

def renderer
  @renderer
end

Instance Method Details

#current_filterObject

The name of the current filter



63
64
65
# File 'lib/webby/filters.rb', line 63

def current_filter
  filters[@processed]
end

#remaining_filtersObject

The list of filters yet to be processed



58
59
60
# File 'lib/webby/filters.rb', line 58

def remaining_filters
  filters[@processed..-1]
end

#start_for(input) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/webby/filters.rb', line 49

def start_for(input)
  filters.inject(input) do |result, filter|
    handler = Filters[filter]
    args = [result, self][0, handler.arity]
    handle(filter, handler, *args)
  end
end