class Content::Pipeline::Filter

Attributes

filters[R]

Public Class Methods

add_filter(*filters) click to toggle source
# File lib/content/pipeline/filters.rb, line 41
def add_filter(*filters)
  @filters ||= []

  filters.each do |f|
    if f.is_a?(Hash)
      f.each do |k, v|
        @filters.push([
          k, v
        ])
      end
    else
      @filters.push([
        f,
        :str
      ])
    end
  end
end
new(str, opts = nil) click to toggle source
# File lib/content/pipeline/filters.rb, line 13
def initialize(str, opts = nil)
  @opts, @str = (opts || {}), str
end

Public Instance Methods

run(next_filter = nil) click to toggle source
# File lib/content/pipeline/filters.rb, line 17
def run(next_filter = nil)
  return @str unless size > 0

  each_with_index do |f, i|
    send(f.first)

    unless size == i + 1 || @str.is_a?(String) || \
        self[i + 1].last == :nokogiri

      @str = @str.to_s
    end
  end

  next_filter = next_filter.filters.first if next_filter
  if ! next_filter || next_filter.last != :nokogiri
    return @str.to_s
  end

  @str
end