Class: Ooh

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/models/sl_user.rb

Instance Method Summary collapse

Instance Method Details

#processObject

general scrubbing of an ooh



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/models/sl_user.rb', line 90

def process
  # process url
  urls = self.text.scan(URL_REGEXP)
  urls.each { |url|
    tiny_url = open("http://tinyurl.com/api-create.php?url=#{url[0]}") {|s| s.read}    
    self.text.sub!(url[0], "<a href='#{tiny_url}'>#{tiny_url}</a>")
  }        
  # process @
  ats = self.text.scan(AT_REGEXP)
  ats.each { |at| self.text.sub!(at, "<a href='/#{at[2,at.length]}'>#{at}</a>") }            
end

#process_dmObject

process direct messages



103
104
105
106
107
# File 'lib/models/sl_user.rb', line 103

def process_dm
  self.recipient = SlUser.first(:email => self.text.split[1])  
  self.text = self.text.split[2..self.text.split.size].join(' ') # remove the first 2 words
  process
end

#process_followObject

process follow commands



110
111
112
113
# File 'lib/models/sl_user.rb', line 110

def process_follow 
  Relationship.create(:SlUser => SlUser.first(:email => self.text.split[1]), :follower => self.SlUser)   
  throw :halt # don't save
end

#starts_with?(prefix) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
118
# File 'lib/models/sl_user.rb', line 115

def starts_with?(prefix)
  prefix = prefix.to_s
  self.text[0, prefix.length] == prefix
end