Class: RedditApi::Users
- Inherits:
-
Object
- Object
- RedditApi::Users
- Defined in:
- lib/reddit_api/users.rb
Constant Summary collapse
- DEFAULT_MAX_MISSES =
2
Instance Attribute Summary collapse
-
#misses ⇒ Object
readonly
Returns the value of attribute misses.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Users
constructor
A new instance of Users.
- #top_posters(subreddit, count) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Users
Returns a new instance of Users.
8 9 10 11 12 13 14 |
# File 'lib/reddit_api/users.rb', line 8 def initialize(args = {}) @post_api = args.fetch(:posts, RedditApi::Posts.new) @user_factory = RedditApi::User @misses = args.fetch(:misses, 0) @max_misses = args.fetch(:max_miss, DEFAULT_MAX_MISSES) @last_count = 0 end |
Instance Attribute Details
#misses ⇒ Object
Returns the value of attribute misses.
6 7 8 |
# File 'lib/reddit_api/users.rb', line 6 def misses @misses end |
Instance Method Details
#top_posters(subreddit, count) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/reddit_api/users.rb', line 16 def top_posters(subreddit, count) users = {} while users.length < count && misses < max_misses posts = post_api.top(subreddit, count) collect_users(posts, count, users) update_misses(users.length) end reset_collection_metrics users.values end |