Class: Plurall::Students
- Inherits:
-
Object
- Object
- Plurall::Students
- Includes:
- Enumerable
- Defined in:
- lib/plurall/students.rb
Overview
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Internal: Returns the GraphQL API response as a GraphQL::Client::Response.
Instance Method Summary collapse
-
#all(&block) ⇒ Object
Public: Iterates all students.
-
#data ⇒ Object
Public: Returns the list of students as a Hash.
-
#each(&block) ⇒ Object
Public: Iterates the list of students.
-
#initialize(response) ⇒ Students
constructor
Internal: Create a new object from a GraphQL API response.
-
#inspect ⇒ Object
Internal: Returns a string representation of the list.
-
#next ⇒ Object
Public: Retrieve the next page of students.
-
#next? ⇒ Boolean
Public: Whether there are more students available.
-
#next_cursor ⇒ Object
Internal: The next cursor used for pagination.
-
#prev ⇒ Object
Public: Retrieve the previous page of students.
-
#prev? ⇒ Boolean
Public: Whether there are previous students available.
-
#prev_cursor ⇒ Object
Internal: The previous cursor used for pagination.
-
#school_id ⇒ Object
Public: Returns the school id for list of students as a String.
-
#total_count ⇒ Object
Public: Returns the number of students as an Integer.
Constructor Details
#initialize(response) ⇒ Students
Internal: Create a new object from a GraphQL API response.
response - The GraphQL API response as a GraphQL::Client::Response.
22 23 24 |
# File 'lib/plurall/students.rb', line 22 def initialize response @response = response end |
Instance Attribute Details
#response ⇒ Object (readonly)
Internal: Returns the GraphQL API response as a GraphQL::Client::Response.
15 16 17 |
# File 'lib/plurall/students.rb', line 15 def response @response end |
Instance Method Details
#all(&block) ⇒ Object
Public: Iterates all students.
Several API calls may be made to retrieve all by repeatedly calling #next until #next? returns ‘false`.
Examples
Plurall.students(school_id: 123456).all do |student|
puts student.name
end
Yields a student object to the block.
Returns an Enumerator when no block argument is given, or nothing when when a block argument is given.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/plurall/students.rb', line 78 def all &block return enum_for :all unless block page = self loop do page.each(&block) page = page.next break if page.nil? end end |
#data ⇒ Object
Public: Returns the list of students as a Hash.
34 35 36 |
# File 'lib/plurall/students.rb', line 34 def data response.data.to_h end |
#each(&block) ⇒ Object
57 58 59 60 61 |
# File 'lib/plurall/students.rb', line 57 def each &block return enum_for :each unless block school_node.students.edges.lazy.map(&:node).each(&block) end |
#inspect ⇒ Object
Internal: Returns a string representation of the list.
171 172 173 |
# File 'lib/plurall/students.rb', line 171 def inspect "#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} students:#{total_count}>" end |
#next ⇒ Object
Public: Retrieve the next page of students.
Returns the next page as Plurall::Students, or nil.
119 120 121 122 123 124 |
# File 'lib/plurall/students.rb', line 119 def next return nil unless next? next_response = Plurall::Api.students school_id: school_id, after: next_cursor self.class.new next_response end |
#next? ⇒ Boolean
99 100 101 |
# File 'lib/plurall/students.rb', line 99 def next? students_page_info.has_next_page end |
#next_cursor ⇒ Object
Internal: The next cursor used for pagination.
Returns the next cursor as a String, or nil.
108 109 110 111 112 |
# File 'lib/plurall/students.rb', line 108 def next_cursor return nil unless next? students_page_info.end_cursor end |
#prev ⇒ Object
161 162 163 164 165 166 |
# File 'lib/plurall/students.rb', line 161 def prev return nil unless prev? prev_response = Plurall::Api.students school_id: school_id, before: prev_cursor self.class.new prev_response end |
#prev? ⇒ Boolean
136 137 138 |
# File 'lib/plurall/students.rb', line 136 def prev? students_page_info.has_previous_page end |
#prev_cursor ⇒ Object
Internal: The previous cursor used for pagination.
Returns the previous cursor as a String, or nil.
145 146 147 148 149 |
# File 'lib/plurall/students.rb', line 145 def prev_cursor return nil unless prev? students_page_info.start_cursor end |
#school_id ⇒ Object
Public: Returns the school id for list of students as a String.
40 41 42 |
# File 'lib/plurall/students.rb', line 40 def school_id school_node.id end |
#total_count ⇒ Object
Public: Returns the number of students as an Integer.
28 29 30 |
# File 'lib/plurall/students.rb', line 28 def total_count school_node.students.total_count end |