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.
-
#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
- #infer_type ⇒ Object
-
#initialize(screen_name) ⇒ TweeterProfile
constructor
A new instance of TweeterProfile.
- #to_s ⇒ Object
- #update_from(tweet) ⇒ Object
Constructor Details
#initialize(screen_name) ⇒ TweeterProfile
Returns a new instance of TweeterProfile.
11 12 13 14 15 16 17 |
# File 'lib/tweeterprofile.rb', line 11 def initialize(screen_name) @tweet_count = 0 @reply_count = 0 @retweet_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 |
#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
40 41 42 43 44 45 46 47 48 |
# File 'lib/tweeterprofile.rb', line 40 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 |
#infer_type ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tweeterprofile.rb', line 50 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 |
#to_s ⇒ Object
35 36 37 38 |
# File 'lib/tweeterprofile.rb', line 35 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
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tweeterprofile.rb', line 19 def update_from(tweet) begin @tweet_count = @tweet_count + 1 if tweet.text.slice(0, 1) == '@' @reply_count = @reply_count + 1 return end @retweet_count = @retweet_count + 1 if tweet.text.slice(0, 2) == 'RT' @link_count = @link_count + 1 if tweet.text.index('http://') != nil rescue NoMethodError => root raise ArgumentError.new("Missing method responses in tweet structure:" + root.to_s) end end |