Class: R18n::CustomFilterList
- Inherits:
-
FilterList
- Object
- FilterList
- R18n::CustomFilterList
- Defined in:
- lib/r18n-core/filter_list.rb
Overview
Filter list for I18n object with custom disabled/enabled filters.
Instance Method Summary collapse
- #active(type) ⇒ Object
- #all(type) ⇒ Object
-
#initialize(on, off) ⇒ CustomFilterList
constructor
A new instance of CustomFilterList.
- #passive(type) ⇒ Object
Methods inherited from FilterList
#enabled, #process, #process_string, #process_typed
Constructor Details
#initialize(on, off) ⇒ CustomFilterList
Returns a new instance of CustomFilterList.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/r18n-core/filter_list.rb', line 109 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 |
Instance Method Details
#active(type) ⇒ Object
142 143 144 145 146 147 |
# File 'lib/r18n-core/filter_list.rb', line 142 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) ⇒ Object
149 150 151 152 153 154 |
# File 'lib/r18n-core/filter_list.rb', line 149 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 |
#passive(type) ⇒ Object
135 136 137 138 139 140 |
# File 'lib/r18n-core/filter_list.rb', line 135 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 |