Module: Virginity::VcardCategories

Included in:
Vcard
Defined in:
lib/virginity/vcard/categories.rb

Overview

methods to handle ALL categories fields in a Vcard. These work around the difficulties of working with multiple CATEGORIES-lines in a vCard by not trying to preserve any ordering or grouping.

Defined Under Namespace

Classes: TagArray

Instance Method Summary collapse

Instance Method Details

#add_category(c) ⇒ Object



15
16
17
18
# File 'lib/virginity/vcard/categories.rb', line 15

def add_category(c)
  @tags = nil
  self.push SeparatedField.new("CATEGORIES", EncodingDecoding::encode_text(c))
end

#category_valuesObject



11
12
13
# File 'lib/virginity/vcard/categories.rb', line 11

def category_values
  categories.map {|cat| cat.values.to_a }.flatten.uniq.sort
end

#in_category?(c) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/virginity/vcard/categories.rb', line 25

def in_category?(c)
  categories.any? { |cat| cat.values.include?(c) }
end

#remove_category(c) ⇒ Object



20
21
22
23
# File 'lib/virginity/vcard/categories.rb', line 20

def remove_category(c)
  @tags = nil
  categories.each { |cat| cat.values.delete(c) }
end

#tag(tag) ⇒ Object



53
54
55
# File 'lib/virginity/vcard/categories.rb', line 53

def tag(tag)
  tags << tag
end

#tagsObject



45
46
47
# File 'lib/virginity/vcard/categories.rb', line 45

def tags
  @tags ||= TagArray.new(self)
end

#tags=(array_of_tags) ⇒ Object



49
50
51
# File 'lib/virginity/vcard/categories.rb', line 49

def tags=(array_of_tags)
  tags.replace(array_of_tags)
end