Class: SimpleTaggable::TagList
- Inherits:
-
Object
- Object
- SimpleTaggable::TagList
- Includes:
- Enumerable
- Defined in:
- lib/simple_taggable/tag_list.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add(*tags) ⇒ Object (also: #<<)
-
#initialize(*tags, filters: [], converters: []) ⇒ TagList
constructor
A new instance of TagList.
- #inspect ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(*tags, filters: [], converters: []) ⇒ TagList
Returns a new instance of TagList.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/simple_taggable/tag_list.rb', line 27 def initialize(*, filters: [], converters: []) @raw_data = [] @filters = filters.freeze @converters = converters.freeze .flatten.each do |tag| if tag.is_a?(TagList) tag.each { |t| add(t) } else add(tag) end end end |
Class Method Details
.[](*tags) ⇒ Object
22 23 24 |
# File 'lib/simple_taggable/tag_list.rb', line 22 def [](*) new(*) end |
Instance Method Details
#add(*tags) ⇒ Object Also known as: <<
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/simple_taggable/tag_list.rb', line 42 def add(*) .flatten.each do |t| tag = @converters.inject(t.to_s) do |pre_tag, converter| converter.call(self, pre_tag) end if @filters.all? { |filter| filter.call(self, tag) } tag.freeze @raw_data << tag end end @raw_data.uniq! self end |
#inspect ⇒ Object
63 64 65 |
# File 'lib/simple_taggable/tag_list.rb', line 63 def inspect "SimpleTaggable::TagList#{raw_data.inspect}" end |
#to_a ⇒ Object
59 60 61 |
# File 'lib/simple_taggable/tag_list.rb', line 59 def to_a @raw_data.deep_dup end |