Module: Annotations::Acts::AnnotationSource::InstanceMethods
- Defined in:
- lib/annotations/acts_as_annotation_source.rb
Overview
This module contains instance methods
Instance Method Summary collapse
- #annotation_source_name ⇒ Object
-
#annotations_by_hash(style = :simple) ⇒ Object
When used with the default style (:simple), returns a Hash of the
annotations_byvalues grouped by attribute name. -
#latest_annotations(limit = nil, include_values = false) ⇒ Object
Helper method to get latest annotations.
Instance Method Details
#annotation_source_name ⇒ Object
75 76 77 78 79 80 |
# File 'lib/annotations/acts_as_annotation_source.rb', line 75 def annotation_source_name %w{ preferred_name display_name title name }.each do |w| return eval("self.#{w}") if self.respond_to?(w) end return "#{self.class.name}_#{self.id}" end |
#annotations_by_hash(style = :simple) ⇒ Object
When used with the default style (:simple), returns a Hash of the annotations_by values grouped by attribute name.
Example output:
"Summary" => "Something interesting happens",
"length" => 345,
"Title" => "Harry Potter and the Exploding Men's Locker Room",
"Tag" => [ "amusing rhetoric", "wizadry" ],
"rating" => "4/5"
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/annotations/acts_as_annotation_source.rb', line 93 def annotations_by_hash(style=:simple) h = { } unless self.annotations_by.blank? self.annotations_by.each do |a| if h.has_key?(a.attribute_name) case h[a.attribute_name] when Array h[a.attribute_name] << a.value_content else h[a.attribute_name] = [ h[a.attribute_name], a.value_content ] end else h[a.attribute_name] = a.value_content end end end return h end |
#latest_annotations(limit = nil, include_values = false) ⇒ Object
Helper method to get latest annotations
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/annotations/acts_as_annotation_source.rb', line 62 def latest_annotations(limit=nil, include_values=false) = { :conditions => { :source_type => self.class.name, :source_id => id }, :order => "updated_at DESC", :limit => limit } [:include] = [ :value ] if include_values Annotation.find(:all, ) end |