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
-
#tags ⇒ Object
Returns the value of attribute tags.
Instance Method Summary collapse
- #add_tags(tags) ⇒ Object (also: #add_tag)
- #add_tags_quick(tags) ⇒ Object (also: #add_tag_quick)
- #init_tags! ⇒ Object
- #remove_tags(*tags) ⇒ Object (also: #remove_tag)
- #tag_values(*tags) ⇒ Object
Instance Attribute Details
#tags ⇒ Object
Returns the value of attribute tags.
13 14 15 |
# File 'lib/selectable/object.rb', line 13 def @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 () @tags.merge! end |
#add_tags_quick(tags) ⇒ Object Also known as: add_tag_quick
19 20 21 |
# File 'lib/selectable/object.rb', line 19 def () @tags.merge! end |
#init_tags! ⇒ Object
37 38 39 |
# File 'lib/selectable/object.rb', line 37 def @tags ||= Selectable::Tags.new end |
#remove_tags(*tags) ⇒ Object Also known as: remove_tag
23 24 25 26 27 |
# File 'lib/selectable/object.rb', line 23 def (*) raise TagsNotInitialized if @tags.nil? .flatten! @tags.delete_if { |n,v| .member?(n) } end |
#tag_values(*tags) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/selectable/object.rb', line 29 def tag_values(*) raise TagsNotInitialized if @tags.nil? .flatten! ret = @tags.collect { |n,v| v if .empty? || .member?(n) }.compact ret end |