Class: Plurall::StudentClasses
- Inherits:
-
Object
- Object
- Plurall::StudentClasses
- Includes:
- Enumerable
- Defined in:
- lib/plurall/student_classes.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 student classes.
-
#data ⇒ Object
Public: Returns the list of classes as a Hash.
-
#each(&block) ⇒ Object
Public: Iterates the list of student classes.
-
#initialize(response) ⇒ StudentClasses
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 classes.
-
#next? ⇒ Boolean
Public: Whether there are more classes available.
-
#next_cursor ⇒ Object
Internal: The next cursor used for pagination.
-
#prev ⇒ Object
Public: Retrieve the previous page of classes.
-
#prev? ⇒ Boolean
Public: Whether there are previous classes available.
-
#prev_cursor ⇒ Object
Internal: The previous cursor used for pagination.
-
#school_id ⇒ Object
Public: Returns the school id for list of classes as a String.
-
#student_id ⇒ Object
Public: Returns the student id for list of classes as a String.
-
#student_uuid ⇒ Object
Public: Returns the student uuid for list of classes as a String.
-
#total_count ⇒ Object
Public: Returns the number of classes as an Integer.
Constructor Details
#initialize(response) ⇒ StudentClasses
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/student_classes.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/student_classes.rb', line 15 def response @response end |
Instance Method Details
#all(&block) ⇒ Object
Public: Iterates all student classes.
Several API calls may be made to retrieve all by repeatedly calling #next until #next? returns ‘false`.
Examples
Plurall.classes(school_id: 123456).all do |school_class|
puts school_class.name
end
Yields a school class object to the block.
Returns an Enumerator when no block argument is given, or nothing when when a block argument is given.
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/plurall/student_classes.rb', line 90 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 classes as a Hash.
34 35 36 |
# File 'lib/plurall/student_classes.rb', line 34 def data response.data.to_h end |
#each(&block) ⇒ Object
69 70 71 72 73 |
# File 'lib/plurall/student_classes.rb', line 69 def each &block return enum_for :each unless block student_node.classes.edges.lazy.map(&:node).each(&block) end |
#inspect ⇒ Object
Internal: Returns a string representation of the list.
183 184 185 |
# File 'lib/plurall/student_classes.rb', line 183 def inspect "#<#{self.class.name}:0x#{(object_id * 2).to_s(16).rjust(16, "0")} classes:#{total_count}>" end |
#next ⇒ Object
Public: Retrieve the next page of classes.
Returns the next page as Plurall::Classes, or nil.
131 132 133 134 135 136 |
# File 'lib/plurall/student_classes.rb', line 131 def next return nil unless next? next_response = Plurall::Api.classes school_id: school_id, after: next_cursor self.class.new next_response end |
#next? ⇒ Boolean
111 112 113 |
# File 'lib/plurall/student_classes.rb', line 111 def next? student_node.classes.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.
120 121 122 123 124 |
# File 'lib/plurall/student_classes.rb', line 120 def next_cursor return nil unless next? student_node.classes.page_info.end_cursor end |
#prev ⇒ Object
173 174 175 176 177 178 |
# File 'lib/plurall/student_classes.rb', line 173 def prev return nil unless prev? prev_response = Plurall::Api.classes school_id: school_id, before: prev_cursor self.class.new prev_response end |
#prev? ⇒ Boolean
148 149 150 |
# File 'lib/plurall/student_classes.rb', line 148 def prev? student_node.classes.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.
157 158 159 160 161 |
# File 'lib/plurall/student_classes.rb', line 157 def prev_cursor return nil unless prev? student_node.classes.page_info.start_cursor end |
#school_id ⇒ Object
Public: Returns the school id for list of classes as a String.
40 41 42 |
# File 'lib/plurall/student_classes.rb', line 40 def school_id school_node.id end |
#student_id ⇒ Object
Public: Returns the student id for list of classes as a String.
52 53 54 |
# File 'lib/plurall/student_classes.rb', line 52 def student_id student_node.id end |
#student_uuid ⇒ Object
Public: Returns the student uuid for list of classes as a String.
46 47 48 |
# File 'lib/plurall/student_classes.rb', line 46 def student_uuid student_node.uuid end |
#total_count ⇒ Object
Public: Returns the number of classes as an Integer.
28 29 30 |
# File 'lib/plurall/student_classes.rb', line 28 def total_count student_node.classes.total_count end |