Class: SimpleHashtag::Hashtag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- SimpleHashtag::Hashtag
- Defined in:
- lib/simple_hashtag/hashtag.rb
Constant Summary collapse
- HASHTAG_REGEX =
TODO Beef up the regex (ie.:what if content is HTML) this is how Twitter does it: github.com/twitter/twitter-text-rb/blob/master/lib/twitter-text/regex.rb
/\s(#([a-z0-9\-_]+))/i
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.clean_orphans ⇒ Object
From DB
32 33 34 35 36 |
# File 'lib/simple_hashtag/hashtag.rb', line 32 def self.clean_orphans # From DB # TODO Make this method call a single SQL query orphans = self.all.select { |h| h.hashtaggables.size == 0 } orphans.map(&:destroy) end |
.find_by_name(name) ⇒ Object
12 13 14 |
# File 'lib/simple_hashtag/hashtag.rb', line 12 def self.find_by_name(name) Hashtag.where("lower(name) =?", name.downcase).first end |
Instance Method Details
#hashtaggables ⇒ Object
24 25 26 |
# File 'lib/simple_hashtag/hashtag.rb', line 24 def hashtaggables self.hashtaggings.collect { |h| h.hashtaggable } end |
#name ⇒ Object
20 21 22 |
# File 'lib/simple_hashtag/hashtag.rb', line 20 def name read_attribute(:name).downcase end |
#name=(val) ⇒ Object
16 17 18 |
# File 'lib/simple_hashtag/hashtag.rb', line 16 def name=(val) write_attribute(:name, val.downcase) end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/simple_hashtag/hashtag.rb', line 28 def to_s name end |