Class: Wuclan::JsonModel::FriendsFollowersParser
- Inherits:
-
GenericJsonParser
- Object
- GenericJsonParser
- Wuclan::JsonModel::FriendsFollowersParser
- Defined in:
- lib/wuclan/twitter/parse/friends_followers_parser.rb
Overview
Friends or Followers is a flat list of users => tweets
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
-
#owning_user_id ⇒ Object
Returns the value of attribute owning_user_id.
-
#scraped_at ⇒ Object
Returns the value of attribute scraped_at.
Attributes inherited from GenericJsonParser
Instance Method Summary collapse
-
#each(&block) ⇒ Object
Enumerate over users (each having one tweet).
- #generate_relationship(user, tweet) ⇒ Object
-
#healthy? ⇒ Boolean
Extracted JSON should be an array.
-
#initialize(raw, context, scraped_at, owning_user_id, *ignore) ⇒ FriendsFollowersParser
constructor
A new instance of FriendsFollowersParser.
Methods inherited from GenericJsonParser
Constructor Details
#initialize(raw, context, scraped_at, owning_user_id, *ignore) ⇒ FriendsFollowersParser
Returns a new instance of FriendsFollowersParser.
10 11 12 13 14 15 |
# File 'lib/wuclan/twitter/parse/friends_followers_parser.rb', line 10 def initialize raw, context, scraped_at, owning_user_id, *ignore super raw self.context = context.to_sym self.scraped_at = scraped_at self.owning_user_id = owning_user_id end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
9 10 11 |
# File 'lib/wuclan/twitter/parse/friends_followers_parser.rb', line 9 def context @context end |
#owning_user_id ⇒ Object
Returns the value of attribute owning_user_id.
9 10 11 |
# File 'lib/wuclan/twitter/parse/friends_followers_parser.rb', line 9 def owning_user_id @owning_user_id end |
#scraped_at ⇒ Object
Returns the value of attribute scraped_at.
9 10 11 |
# File 'lib/wuclan/twitter/parse/friends_followers_parser.rb', line 9 def scraped_at @scraped_at end |
Instance Method Details
#each(&block) ⇒ Object
Enumerate over users (each having one tweet)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/wuclan/twitter/parse/friends_followers_parser.rb', line 32 def each &block raw.each do |hsh| case context when :favorites then parsed = JsonTweet.new( hsh, nil) else parsed = JsonTwitterUser.new(hsh, scraped_at) end next unless parsed && parsed.healthy? user_b = parsed.generate_user_partial tweet = parsed.generate_tweet [ user_b, tweet, generate_relationship(user_b, tweet) ].compact.each do |obj| yield obj end end end |
#generate_relationship(user, tweet) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/wuclan/twitter/parse/friends_followers_parser.rb', line 20 def generate_relationship user, tweet case context when :followers then AFollowsB.new( user.id, owning_user_id) when :friends then AFollowsB.new( owning_user_id, user.id) when :favorites then AFavoritesB.new(owning_user_id, user.id, (tweet ? tweet.id : nil)) else raise "Can't make a relationship out of #{context}. Perhaps better communication is the key." end end |
#healthy? ⇒ Boolean
Extracted JSON should be an array
18 |
# File 'lib/wuclan/twitter/parse/friends_followers_parser.rb', line 18 def healthy?() raw && raw.is_a?(Array) end |