Class: NotionRubyMapping::List

Inherits:
Base
  • Object
show all
Includes:
Enumerable
Defined in:
lib/notion_ruby_mapping/list.rb

Overview

Notion List object

Instance Attribute Summary collapse

Attributes inherited from Base

#id, #json

Instance Method Summary collapse

Methods inherited from Base

#[], #assign_property, #children, create_from_json, #icon, #json_properties, #new_record?, #properties, #property_values_json, #reload, #restore_from_json, #save, #set_icon, #title, #update_json

Constructor Details

#initialize(json: nil, id: nil, database: nil, query: nil) ⇒ List

Returns a new instance of List.



8
9
10
11
12
13
14
15
16
# File 'lib/notion_ruby_mapping/list.rb', line 8

def initialize(json: nil, id: nil, database: nil, query: nil)
  super(json: json, id: id)
  @has_more = @json["has_more"]
  @load_all_contents = !@has_more
  @database = database
  @query = query
  @index = 0
  @has_content = true
end

Instance Attribute Details

#has_moreObject (readonly)

Returns the value of attribute has_more.



17
18
19
# File 'lib/notion_ruby_mapping/list.rb', line 17

def has_more
  @has_more
end

Instance Method Details

#eachObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/notion_ruby_mapping/list.rb', line 19

def each
  return enum_for(:each) unless block_given?

  if @database
    unless @has_content # re-exec
      unless @load_all_contents
        @query.start_cursor = nil
        @json = @database.query_database @query
        @has_more = @json["has_more"]
      end
      @index = 0
      @has_content = true
    end

    while @has_content
      if @index < results.length
        object = Base.create_from_json(results[@index])
        @index += 1
        yield object
      elsif @has_more
        if @database
          @query.start_cursor = @json["next_cursor"]
          @json = @database.query_database @query
          @index = 0
          @has_more = @json["has_more"]
        else
          @has_content = false
        end
      else
        @has_content = false
      end
    end
  end
end