Class: FellowshipOne::PersonList
- Inherits:
-
Object
- Object
- FellowshipOne::PersonList
- Includes:
- Enumerable
- Defined in:
- lib/api/person_list.rb
Instance Attribute Summary collapse
-
#additional_pages ⇒ Object
readonly
Returns the value of attribute additional_pages.
-
#count ⇒ Object
(also: #size)
readonly
Returns the value of attribute count.
-
#page_number ⇒ Object
readonly
Returns the value of attribute page_number.
-
#total_records ⇒ Object
readonly
Returns the value of attribute total_records.
Instance Method Summary collapse
-
#[](index) ⇒ Person
Get the specified person.
-
#all_names ⇒ Object
(also: #names)
All the people in the list.
-
#each(&block) ⇒ Object
This method is needed for Enumerable.
-
#empty? ⇒ Boolean
Checks if the list is empty.
-
#ids ⇒ Object
Get all the people ids in the list.
-
#initialize(options) ⇒ PersonList
constructor
Constructor.
-
#raw_data ⇒ Object
Access to the raw JSON data.
Constructor Details
#initialize(options) ⇒ PersonList
Constructor.
Options: :page - (optional) The page number to get. :reader - (optional) The Reader to use to load the data.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/api/person_list.rb', line 17 def initialize() #options[:page] ||= 1 reader = [:reader] || FellowshipOne::PersonListReader.new() @json_data = reader.load_feed @count = @json_data['@count'].to_i @page_number = @json_data['@pageNumber'].to_i @total_records = @json_data['@totalRecords'].to_i @additional_pages = @json_data['@additionalPages'].to_i end |
Instance Attribute Details
#additional_pages ⇒ Object (readonly)
Returns the value of attribute additional_pages.
7 8 9 |
# File 'lib/api/person_list.rb', line 7 def additional_pages @additional_pages end |
#count ⇒ Object (readonly) Also known as: size
Returns the value of attribute count.
7 8 9 |
# File 'lib/api/person_list.rb', line 7 def count @count end |
#page_number ⇒ Object (readonly)
Returns the value of attribute page_number.
7 8 9 |
# File 'lib/api/person_list.rb', line 7 def page_number @page_number end |
#total_records ⇒ Object (readonly)
Returns the value of attribute total_records.
7 8 9 |
# File 'lib/api/person_list.rb', line 7 def total_records @total_records end |
Instance Method Details
#[](index) ⇒ Person
Get the specified person.
45 46 47 |
# File 'lib/api/person_list.rb', line 45 def [](index) Person.new( @json_data['person'][index] ) if @json_data['person'] and @json_data['person'][index] end |
#all_names ⇒ Object Also known as: names
All the people in the list.
32 33 34 35 |
# File 'lib/api/person_list.rb', line 32 def all_names return [] unless @json_data['person'] @json_data['person'].collect { |person| [person['firstName'], person['lastName']].join(' ') } end |
#each(&block) ⇒ Object
This method is needed for Enumerable.
51 52 53 |
# File 'lib/api/person_list.rb', line 51 def each &block @json_data['person'].each{ |person| yield( Person.new(person) )} end |
#empty? ⇒ Boolean
Checks if the list is empty.
61 62 63 64 |
# File 'lib/api/person_list.rb', line 61 def empty? #@json_data['person'].empty? self.count == 0 ? true : false end |
#ids ⇒ Object
Get all the people ids in the list.
70 71 72 |
# File 'lib/api/person_list.rb', line 70 def ids (@json_data['person'].collect { |person| person['@id'] }).uniq end |
#raw_data ⇒ Object
Access to the raw JSON data. This method is needed for merging lists.
78 79 80 |
# File 'lib/api/person_list.rb', line 78 def raw_data @json_data end |