class Supertag::Hashtag

Constants

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

Public Class Methods

clean_orphans() click to toggle source
# File lib/supertag/hashtag.rb, line 56
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) click to toggle source
# File lib/supertag/hashtag.rb, line 14
def self.find_by_name(name)
  Hashtag.where("lower(name) =?", name.downcase).first
end
find_or_create_by_name(name, &block) click to toggle source
# File lib/supertag/hashtag.rb, line 18
def self.find_or_create_by_name(name, &block)
  find_by_name(name) || create(name: name, &block)
end

Public Instance Methods

hashtaggables() click to toggle source
# File lib/supertag/hashtag.rb, line 31
def hashtaggables
  self.hashtaggings.includes(:hashtaggable).collect { |h| h.hashtaggable }
end
hashtagged_ids_by_types() click to toggle source
# File lib/supertag/hashtag.rb, line 39
def hashtagged_ids_by_types
  hashtagged_ids ||= {}
  self.hashtaggings.each do |h|
    hashtagged_ids[h.hashtaggable_type] ||= Array.new
    hashtagged_ids[h.hashtaggable_type] << h.hashtaggable_id
  end
  hashtagged_ids
end
hashtagged_ids_for_type(type) click to toggle source
# File lib/supertag/hashtag.rb, line 48
def hashtagged_ids_for_type(type)
  hashtagged_ids_by_types[type]
end
hashtagged_types() click to toggle source
# File lib/supertag/hashtag.rb, line 35
def hashtagged_types
  self.hashtaggings.pluck(:hashtaggable_type).uniq
end
name() click to toggle source
# File lib/supertag/hashtag.rb, line 27
def name
  read_attribute(:name).downcase
end
name=(val) click to toggle source
# File lib/supertag/hashtag.rb, line 23
def name=(val)
  write_attribute(:name, val.downcase)
end
to_s() click to toggle source
# File lib/supertag/hashtag.rb, line 52
def to_s
  name
end