Class: TwitterType::TypeInferrer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTypeInferrer

Returns a new instance of TypeInferrer.



10
11
12
# File 'lib/twittertypeinferrer.rb', line 10

def initialize()
  @client = TwitterClientWrapper.new
end

Instance Attribute Details

#client=(value) ⇒ Object (writeonly)

Sets the attribute client

Parameters:

  • value

    the value to set the attribute client to.



7
8
9
# File 'lib/twittertypeinferrer.rb', line 7

def client=(value)
  @client = value
end

#profileObject (readonly)

Returns the value of attribute profile.



8
9
10
# File 'lib/twittertypeinferrer.rb', line 8

def profile
  @profile
end

Instance Method Details

#infer(user) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/twittertypeinferrer.rb', line 14

def infer(user)
  begin
    tweets = @client.gather_recent_tweets_for(user)
    @profile = ProfileFactory.new(user).build(tweets)
    @profile.infer_type
  rescue TwitterType::ProtectedUserAccessError => error
    @profile = ProfileFactory.new(user).build([])
    @profile.inferred_type = :unknown_protected_user
  rescue TwitterType::InvalidUserAccessError => error
    @profile = ProfileFactory.new(user).build([])
    @profile.inferred_type = :unknown_user
  end

  self
end