Module: Atom::HasCategories

Included in:
Entry, Feed
Defined in:
lib/atom/entry.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



25
26
27
# File 'lib/atom/entry.rb', line 25

def HasCategories.included(klass)
  klass.atom_elements :category, :categories, Atom::Category
end

Instance Method Details

#tag_with(tags, delimiter = ' ') ⇒ Object

categorize the entry with each of an array or a space-separated

string


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/atom/entry.rb', line 31

def tag_with(tags, delimiter = ' ')
  return if not tags or tags.empty?

  tag_list = unless tags.is_a?(String)
               tags
             else
               tags = tags.split(delimiter)
               tags.map! { |t| t.strip }
               tags.reject! { |t| t.empty? }
               tags.uniq
             end

  tag_list.each do |tag|
    unless categories.any? { |c| c.term == tag }
      categories.new :term => tag
    end
  end
end