Class: Tag

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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



44
45
46
# File 'lib/glue/taggable.rb', line 44

def self.total_frequency(tags = Tag.all)
  tags.inject(1) { |total, t| total += t.count }
end

Instance Method Details

#tag(obj) ⇒ Object

– FIXME: use update_properties here! ++



27
28
29
30
31
32
33
34
# File 'lib/glue/taggable.rb', line 27

def tag(obj)
  class_name = obj.class.name
  method_name = class_name.index('::') ? (class_name =~ /.*?\:\:(.*)/; $1) : class_name

  send(method_name.pluralize.underscore.to_sym) << obj
  @count += 1
  save!
end

#taggedObject

Return all tagged objects from all categories.



38
39
40
# File 'lib/glue/taggable.rb', line 38

def tagged
  # TODO.  
end

#to_sObject



48
49
50
# File 'lib/glue/taggable.rb', line 48

def to_s
  @name
end