Class: Tag
- Inherits:
-
Object
- Object
- Tag
- Defined in:
- lib/glue/taggable.rb
Overview
The default Tag implementation. A tag attaches semantics to a given object. – FIXME: use index and char() instead of String. ++
Class Method Summary collapse
-
.total_frequency(tags = Tag.all) ⇒ Object
Helper method.
Instance Method Summary collapse
-
#initialize(name = nil) ⇒ Tag
constructor
A new instance of Tag.
-
#tag(obj) ⇒ Object
(also: #link)
Tag an object.
-
#tagged ⇒ Object
Return all tagged objects from all categories.
- #to_s ⇒ Object
-
#untag(obj = nil) ⇒ Object
(also: #unlink)
Untags an object.
Constructor Details
#initialize(name = nil) ⇒ Tag
Returns a new instance of Tag.
18 19 20 21 |
# File 'lib/glue/taggable.rb', line 18 def initialize(name = nil) @name = name @count = 0 end |
Class Method Details
.total_frequency(tags = Tag.all) ⇒ Object
Helper method
75 76 77 |
# File 'lib/glue/taggable.rb', line 75 def self.total_frequency( = Tag.all) .inject(1) { |total, t| total += t.count } end |
Instance Method Details
#tag(obj) ⇒ Object Also known as: link
Tag an object.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/glue/taggable.rb', line 25 def tag(obj) #-- # FIXME: this does not work as expected :( it alters # the @loaded flag in the obj.tags collection without # setting the @members. # INVESTIGATE: why this happens! # # return if obj.tagged_with?(@name) # class_name = obj.class.name # method_name = class_name.index('::') ? (class_name =~ /.*?\:\:(.*)/; $1) : class_name # send(method_name.pluralize.underscore.to_sym) << obj #++ unless obj.tagged_with?(name) obj. << self @count += 1 update_property :count end end |
#tagged ⇒ Object
Return all tagged objects from all categories.
69 70 71 |
# File 'lib/glue/taggable.rb', line 69 def tagged # TODO. end |
#to_s ⇒ Object
79 80 81 |
# File 'lib/glue/taggable.rb', line 79 def to_s @name end |
#untag(obj = nil) ⇒ Object Also known as: unlink
Untags an object. If no object is passed, it just decrements the (reference) count. If the count reaches 0 the tag is deleted (garbage collection).
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/glue/taggable.rb', line 50 def untag(obj = nil) if obj # TODO: implement me. end @count -= 1 if @count > 0 p "-- dec ref count" update_property :count else p "-- count = 0 -> delete" self.delete() end end |