Class: Plurall::StudentClasses

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/plurall/student_classes.rb

Overview

Public: A list of school classes that supports pagination.

Examples

Plurall.classes(school_id: 123456).each do |school_class|
  puts school_class.name
end

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#responseObject (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

#dataObject

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

Public: Iterates the list of student classes.

Examples

Plurall.classes(school_id: 123456).each 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.



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

#inspectObject

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

#nextObject

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

Public: Whether there are more classes available.

Examples

classes = Plurall.classes school_id: 123456
classes.next?

Returns true or false.

Returns:

  • (Boolean)


111
112
113
# File 'lib/plurall/student_classes.rb', line 111

def next?
  student_node.classes.page_info.has_next_page
end

#next_cursorObject

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

#prevObject

Public: Retrieve the previous page of classes.

Examples

classes = Plurall.classes school_id: 123456
prev_classes = classes.prev

Returns the previous page as Plurall::Classes, or nil.



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

Public: Whether there are previous classes available.

Examples

classes = Plurall.classes school_id: 123456
classes.prev?

Returns true or false.

Returns:

  • (Boolean)


148
149
150
# File 'lib/plurall/student_classes.rb', line 148

def prev?
  student_node.classes.page_info.has_previous_page
end

#prev_cursorObject

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_idObject

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_idObject

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_uuidObject

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_countObject

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