Class: TheCity::UserList
- Includes:
- Enumerable
- Defined in:
- lib/api/user_list.rb
Instance Attribute Summary
Attributes inherited from ApiList
#current_page, #per_page, #total_entries, #total_pages
Instance Method Summary collapse
-
#[](index) ⇒ User
Get the specified user.
-
#all_names ⇒ Object
(also: #names)
All the users in the list.
-
#each(&block) ⇒ Object
This method is needed for Enumerable.
-
#empty? ⇒ Boolean
Checks if the list is empty.
-
#initialize(options = {}) ⇒ UserList
constructor
Constructor.
Methods inherited from ApiList
load, #next_page, #next_page!, #next_page?
Constructor Details
#initialize(options = {}) ⇒ UserList
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/api/user_list.rb', line 21 def initialize( = {}) @options = .clone @options[:page] ||= 1 @options[:per_page] ||= 200 @options[:reader] = TheCity::UserListReader.new(@options) if @options[:reader].nil? @json_data = @options[:reader].load_feed @total_entries = @json_data['total_entries'] @total_pages = @json_data['total_pages'] @per_page = @json_data['per_page'] @current_page = @json_data['current_page'] end |
Instance Method Details
#[](index) ⇒ User
Get the specified user.
50 51 52 |
# File 'lib/api/user_list.rb', line 50 def [](index) User.new( @json_data['users'][index] ) if @json_data['users'] and @json_data['users'][index] end |
#all_names ⇒ Object Also known as: names
All the users in the list.
38 39 40 41 |
# File 'lib/api/user_list.rb', line 38 def all_names return [] unless @json_data['users'] @json_data['users'].collect { |user| [user['first'], user['last']].join(' ') } end |
#each(&block) ⇒ Object
This method is needed for Enumerable.
56 57 58 |
# File 'lib/api/user_list.rb', line 56 def each &block @json_data['users'].each{ |user| yield( User.new(user) )} end |
#empty? ⇒ Boolean
Checks if the list is empty.
66 67 68 |
# File 'lib/api/user_list.rb', line 66 def empty? @json_data['users'].empty? end |