class Supertag::Usertag

Constants

USERTAG_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/usertag.rb, line 57
def self.clean_orphans # From DB
  # TODO Make this method call a single SQL query
  orphans = self.all.select { |h| h.usertaggables.size == 0 }
  orphans.map(&:destroy)
end
find_by_name(name) click to toggle source
# File lib/supertag/usertag.rb, line 15
def self.find_by_name(name)
  Usertag.where("lower(name) =?", name.downcase).first
end
find_or_create_by_name(name, &block) click to toggle source
# File lib/supertag/usertag.rb, line 19
def self.find_or_create_by_name(name, &block)
  find_by_name(name) || create(name: name, &block)
end

Public Instance Methods

name() click to toggle source
# File lib/supertag/usertag.rb, line 28
def name
  read_attribute(:name).downcase
end
name=(val) click to toggle source
# File lib/supertag/usertag.rb, line 24
def name=(val)
  write_attribute(:name, val.downcase)
end
to_s() click to toggle source
# File lib/supertag/usertag.rb, line 53
def to_s
  name
end
usertaggables() click to toggle source
# File lib/supertag/usertag.rb, line 32
def usertaggables
  self.usertaggings.includes(:usertaggable).collect { |h| h.usertaggable }
end
usertagged_ids_by_types() click to toggle source
# File lib/supertag/usertag.rb, line 40
def usertagged_ids_by_types
  usertagged_ids ||= {}
  self.usertaggings.each do |h|
    usertagged_ids[h.usertaggable_type] ||= Array.new
    usertagged_ids[h.usertaggable_type] << h.usertaggable_id
  end
  usertagged_ids
end
usertagged_ids_for_type(type) click to toggle source
# File lib/supertag/usertag.rb, line 49
def usertagged_ids_for_type(type)
  usertagged_ids_by_types[type]
end
usertagged_types() click to toggle source
# File lib/supertag/usertag.rb, line 36
def usertagged_types
  self.usertaggings.pluck(:usertaggable_type).uniq
end