R18n::CustomFilterList

Filter list for I18n object with custom disabled/enabled filters.

Public Class Methods

new(on, off) click to toggle source
# File lib/r18n-core/filter_list.rb, line 113
def initialize(on, off)
  @on  = Array(on).map  { |i| Filters.defined[i] }
  @off = Array(off).map { |i| Filters.defined[i] }
  @changed_types = (@on + @off).map { |i| i.types }.flatten.uniq

  @changed_passive = (@on + @off).reject { |i| !i.passive? }.
    map { |i| i.types }.flatten.uniq
  @changed_active  = (@on + @off).reject { |i|  i.passive? }.
    map { |i| i.types }.flatten.uniq

  @on_by_type = {}
  @on.each do |filter|
    filter.types.each do |type|
      @on_by_type[type] ||= []
      @on_by_type[type] << filter
    end
  end
  @off_by_type = {}
  @off.each do |filter|
    filter.types.each do |type|
      @off_by_type[type] ||= []
      @off_by_type[type] << filter
    end
  end
end

Public Instance Methods

active(type) click to toggle source
# File lib/r18n-core/filter_list.rb, line 146
def active(type)
  enabled = Filters.active_enabled[type]
  return enabled unless @changed_active.include? type
  enabled  = enabled.reject { |i| @off_by_type[type].include? i }
  enabled += @on_by_type[type].reject { |i|  i.passive }
end
all(type) click to toggle source
# File lib/r18n-core/filter_list.rb, line 153
def all(type)
  enabled = Filters.enabled[type]
  return enabled unless @changed_types.include? type
  enabled  = enabled.reject { |i| @off_by_type[type].include? i }
  enabled += @on_by_type[type]
end
hash() click to toggle source
# File lib/r18n-core/filter_list.rb, line 160
def hash
  [@on, @off].hash
end
passive(type) click to toggle source
# File lib/r18n-core/filter_list.rb, line 139
def passive(type)
  enabled = Filters.passive_enabled[type]
  return enabled unless @changed_passive.include? type
  enabled  = enabled.reject { |i| @off_by_type[type].include? i }
  enabled += @on_by_type[type].reject { |i| !i.passive }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.