0
+class Tweet < DataMapper::Base
0
+ property :twitter_id, :string, :nullable => false
0
+ property :text, :string, :nullable => false, :length => 140
0
+ property :source, :string, :nullable => false
0
+ property :in_reply_to, :string, :length => 140
0
+ property :username, :string, :nullable => false, :length => 255
0
+ property :created_at, :datetime, :nullable => false
0
+ validates_presence_of :twitter_id, :key => "uniq_twitter_id"
0
+ validates_presence_of :text, :key => "uniq_text"
0
+ validates_presence_of :source, :key => "uniq_source"
0
+ validates_presence_of :created_at, :key => "uniq_created_at"
0
+ # This returns true if the tweet is a reply to someone, false if it isn't
0
+ !self.in_reply_to.nil?
0
+ # This returns the user that was being replied to if this was a reply
0
+ return nil unless self.reply?
0
+ user = self.text[0...self.text.index(" ")]
0
+ return nil unless user[0...1] == "@"
0
+ # This provides a summary of the text update, if it's longer than 30 characters
0
+ summary = summary[(summary.index(" ") + 1)...summary.length] if self.text[0...1] == "@"
0
+ summary = (summary.length > 30 ? "#{summary[0..30]}..." : summary[0..30])
0
+ # This returns any tweets found between two articles
0
+ def self.find_between_articles(before, after)
0
+ settings = TwitterSetting.current
0
+ Tweet.all.select { |t| t.created_at < before.published_at && t.created_at > after.published_at }.select { |t| (t.reply? && settings.ignore_replies) ? false : true }
0
+ # This builds a direct url to the tweet
0
+ "http://twitter.com/#{self.username}/statuses/#{self.twitter_id}"
Comments
No one has commented yet.