Class: TwitterType::TweeterProfile

Inherits:
Object
  • Object
show all
Defined in:
lib/tweeterprofile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_typeObject

Returns the value of attribute inferred_type.



4
5
6
# File 'lib/tweeterprofile.rb', line 4

def inferred_type
  @inferred_type
end

Returns the value of attribute link_count.



4
5
6
# File 'lib/tweeterprofile.rb', line 4

def link_count
  @link_count
end

#reply_countObject

Returns the value of attribute reply_count.



4
5
6
# File 'lib/tweeterprofile.rb', line 4

def reply_count
  @reply_count
end

#retweet_countObject

Returns the value of attribute retweet_count.



4
5
6
# File 'lib/tweeterprofile.rb', line 4

def retweet_count
  @retweet_count
end

#screen_nameObject

Returns the value of attribute screen_name.



4
5
6
# File 'lib/tweeterprofile.rb', line 4

def screen_name
  @screen_name
end

#tweet_countObject

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_typeObject

Raises:

  • (ArgumentError)


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_sObject



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