Class: Ebooks::Conversation
- Inherits:
-
Object
- Object
- Ebooks::Conversation
- Defined in:
- lib/twitter_ebooks/bot.rb
Overview
Represents a single reply tree of tweets
Instance Attribute Summary collapse
-
#last_update ⇒ Object
readonly
Returns the value of attribute last_update.
Instance Method Summary collapse
- #add(tweet) ⇒ Object
-
#can_include?(username) ⇒ Boolean
Figure out whether to keep this user in the reply prefix We want to avoid spamming non-participating users.
-
#initialize(bot) ⇒ Conversation
constructor
A new instance of Conversation.
-
#is_bot?(username) ⇒ Boolean
Make an informed guess as to whether a user is a bot based on their behavior in this conversation.
Constructor Details
#initialize(bot) ⇒ Conversation
Returns a new instance of Conversation.
14 15 16 17 18 |
# File 'lib/twitter_ebooks/bot.rb', line 14 def initialize(bot) @bot = bot @tweets = [] @last_update = Time.now end |
Instance Attribute Details
#last_update ⇒ Object (readonly)
Returns the value of attribute last_update.
11 12 13 |
# File 'lib/twitter_ebooks/bot.rb', line 11 def last_update @last_update end |
Instance Method Details
#add(tweet) ⇒ Object
21 22 23 24 |
# File 'lib/twitter_ebooks/bot.rb', line 21 def add(tweet) @tweets << tweet @last_update = Time.now end |
#can_include?(username) ⇒ Boolean
Figure out whether to keep this user in the reply prefix We want to avoid spamming non-participating users
42 43 44 45 |
# File 'lib/twitter_ebooks/bot.rb', line 42 def can_include?(username) @tweets.length <= 4 || !@tweets.select { |t| t.user.screen_name.downcase == username.downcase }.empty? end |
#is_bot?(username) ⇒ Boolean
Make an informed guess as to whether a user is a bot based on their behavior in this conversation
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/twitter_ebooks/bot.rb', line 28 def is_bot?(username) usertweets = @tweets.select { |t| t.user.screen_name.downcase == username.downcase } if usertweets.length > 2 if (usertweets[-1].created_at - usertweets[-3].created_at) < 10 return true end end username.include?("ebooks") end |