Class: EasyTag::Tag

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/easy_tag/tag.rb

Class Method Summary collapse

Class Method Details

.compact_tag_list(tag_list, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/models/easy_tag/tag.rb', line 6

def self.compact_tag_list(tag_list, options = {})
  options.reverse_merge! :downcase => true, 
                         :delimiter => ','
  if (tag_list.is_a?(String))
    tag_list.downcase! if options[:downcase]
    tags = tag_list.to_tags(options[:delimiter])
  elsif (tag_list.is_a?(Array))
    if options[:downcase]
      tags = tag_list.collect { |t| t.downcase }
    else
      tags = tag_list
    end
  elsif tag_list.blank?
    tags = nil
  else
    raise EasyTag::InvalidTagList
  end

  tags
end