Class: TwitterType::TweeterProfile
- Inherits:
-
Object
- Object
- TwitterType::TweeterProfile
- Defined in:
- lib/tweeterprofile.rb
Instance Attribute Summary collapse
-
#inferred_type ⇒ Object
Returns the value of attribute inferred_type.
-
#link_count ⇒ Object
Returns the value of attribute link_count.
-
#original_count ⇒ Object
Returns the value of attribute original_count.
-
#reply_count ⇒ Object
Returns the value of attribute reply_count.
-
#retweet_count ⇒ Object
Returns the value of attribute retweet_count.
-
#screen_name ⇒ Object
Returns the value of attribute screen_name.
-
#tweet_count ⇒ Object
Returns the value of attribute tweet_count.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #has_link?(tweet) ⇒ Boolean
- #infer_type ⇒ Object
-
#initialize(screen_name) ⇒ TweeterProfile
constructor
A new instance of TweeterProfile.
- #reply?(tweet) ⇒ Boolean
- #retweet?(tweet) ⇒ Boolean
- #to_s ⇒ Object
- #update_from(tweet) ⇒ Object
Constructor Details
#initialize(screen_name) ⇒ TweeterProfile
Returns a new instance of TweeterProfile.
12 13 14 15 16 17 18 19 |
# File 'lib/tweeterprofile.rb', line 12 def initialize(screen_name) @tweet_count = 0 @reply_count = 0 @retweet_count = 0 @original_count = 0 @link_count = 0 @screen_name = screen_name end |
Instance Attribute Details
#inferred_type ⇒ Object
Returns the value of attribute inferred_type.
4 5 6 |
# File 'lib/tweeterprofile.rb', line 4 def inferred_type @inferred_type end |
#link_count ⇒ Object
Returns the value of attribute link_count.
4 5 6 |
# File 'lib/tweeterprofile.rb', line 4 def link_count @link_count end |
#original_count ⇒ Object
Returns the value of attribute original_count.
4 5 6 |
# File 'lib/tweeterprofile.rb', line 4 def original_count @original_count end |
#reply_count ⇒ Object
Returns the value of attribute reply_count.
4 5 6 |
# File 'lib/tweeterprofile.rb', line 4 def reply_count @reply_count end |
#retweet_count ⇒ Object
Returns the value of attribute retweet_count.
4 5 6 |
# File 'lib/tweeterprofile.rb', line 4 def retweet_count @retweet_count end |
#screen_name ⇒ Object
Returns the value of attribute screen_name.
4 5 6 |
# File 'lib/tweeterprofile.rb', line 4 def screen_name @screen_name end |
#tweet_count ⇒ Object
Returns the value of attribute tweet_count.
4 5 6 |
# File 'lib/tweeterprofile.rb', line 4 def tweet_count @tweet_count end |
Instance Method Details
#==(other) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/tweeterprofile.rb', line 56 def ==(other) result = @screen_name == other.screen_name result = result && @tweet_count == other.tweet_count result = result && @reply_count == other.reply_count result = result && @retweet_count == other.retweet_count result = result && @link_count == other.link_count return result end |
#has_link?(tweet) ⇒ Boolean
43 44 45 |
# File 'lib/tweeterprofile.rb', line 43 def has_link?(tweet) tweet.text.index('http://') != nil end |
#infer_type ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/tweeterprofile.rb', line 66 def infer_type attributes = [@retweet_count, @link_count, @reply_count] highest_count = attributes.max raise ArgumentError if @tweet_count < highest_count @inferred_type = set_type(highest_count) return @inferred_type end |
#reply?(tweet) ⇒ Boolean
47 48 49 |
# File 'lib/tweeterprofile.rb', line 47 def reply?(tweet) tweet.text.slice(0, 1) == '@' end |
#retweet?(tweet) ⇒ Boolean
39 40 41 |
# File 'lib/tweeterprofile.rb', line 39 def retweet?(tweet) tweet.text.slice(0, 2) == 'RT' end |
#to_s ⇒ Object
51 52 53 54 |
# File 'lib/tweeterprofile.rb', line 51 def to_s type_to_s = (@inferred_type ? "type " + @inferred_type.inspect + ", " : "") @screen_name + ": " + type_to_s + "#tweets " + @tweet_count.to_s + ", #replies " + @reply_count.to_s + ", #retweets " + @retweet_count.to_s + ", #links " + @link_count.to_s + "\n" end |
#update_from(tweet) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/tweeterprofile.rb', line 21 def update_from(tweet) begin @tweet_count = @tweet_count + 1 if reply?(tweet) @reply_count = @reply_count + 1 return end @retweet_count = @retweet_count + 1 if retweet?(tweet) @link_count = @link_count + 1 if has_link?(tweet) @original_count = @original_count + 1 if !retweet?(tweet) && !reply?(tweet) rescue NoMethodError => root raise ArgumentError.new("Missing method responses in tweet structure:" + root.to_s) end end |