Module: Selectable::Object

Included in:
Benelux::Mark, Benelux::MethodPacker, Benelux::Range, Benelux::Stats::Calculator, TaggableString
Defined in:
lib/selectable/object.rb

Overview

Helper methods for objects with a @tags instance var

e.g.

class Something
  include Selectable::Object
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#tagsObject

Returns the value of attribute tags.



13
14
15
# File 'lib/selectable/object.rb', line 13

def tags
  @tags
end

Instance Method Details

#add_tags(tags) ⇒ Object Also known as: add_tag



14
15
16
17
# File 'lib/selectable/object.rb', line 14

def add_tags(tags)
  init_tags!
  @tags.merge! tags
end

#add_tags_quick(tags) ⇒ Object Also known as: add_tag_quick



19
20
21
# File 'lib/selectable/object.rb', line 19

def add_tags_quick(tags)
  @tags.merge! tags
end

#init_tags!Object



37
38
39
# File 'lib/selectable/object.rb', line 37

def init_tags!
  @tags ||= Selectable::Tags.new
end

#remove_tags(*tags) ⇒ Object Also known as: remove_tag

Raises:



23
24
25
26
27
# File 'lib/selectable/object.rb', line 23

def remove_tags(*tags)
  raise TagsNotInitialized if @tags.nil?
  tags.flatten!
  @tags.delete_if { |n,v| tags.member?(n) }
end

#tag_values(*tags) ⇒ Object

Raises:



29
30
31
32
33
34
35
36
# File 'lib/selectable/object.rb', line 29

def tag_values(*tags)
  raise TagsNotInitialized if @tags.nil?
  tags.flatten!
  ret = @tags.collect { |n,v| 
    v if tags.empty? || tags.member?(n) 
  }.compact
  ret
end