Class: NotionRubyMapping::List
- Includes:
- Enumerable
- Defined in:
- lib/notion_ruby_mapping/blocks/list.rb
Overview
Notion List object
Instance Attribute Summary collapse
-
#has_more ⇒ Object
readonly
Returns the value of attribute has_more.
Attributes inherited from Base
Instance Method Summary collapse
- #each ⇒ NotionRubyMapping::List, Enumerator
-
#initialize(json: nil, id: nil, database: nil, parent: nil, property: nil, query: nil) ⇒ List
constructor
A new instance of List.
Methods inherited from Base
#append_block_children, #assert_parent_children_pair, #assign_property, #block?, #children, create_from_json, #created_time, #database?, dry_run_script, #get, #icon, #inspect, #json_properties, #last_edited_time, #new_record?, #page?, #parent, #properties, #property_values_json, #reload, #restore_from_json, #save, #set_icon, #synced_block_original?, #update_json
Constructor Details
#initialize(json: nil, id: nil, database: nil, parent: nil, property: nil, query: nil) ⇒ List
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/notion_ruby_mapping/blocks/list.rb', line 8 def initialize(json: nil, id: nil, database: nil, parent: nil, property: nil, query: nil) super(json: json, id: id) @has_more = @json["has_more"] @load_all_contents = !@has_more @database = database @parent = parent @property = property @query = query @index = 0 @has_content = true end |
Instance Attribute Details
#has_more ⇒ Object (readonly)
Returns the value of attribute has_more.
19 20 21 |
# File 'lib/notion_ruby_mapping/blocks/list.rb', line 19 def has_more @has_more end |
Instance Method Details
#each ⇒ NotionRubyMapping::List, Enumerator
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/notion_ruby_mapping/blocks/list.rb', line 23 def each return enum_for(:each) unless block_given? if @parent unless @has_content unless @load_all_contents @query.start_cursor = nil @json = @parent.children @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 @parent @query.start_cursor = @json["next_cursor"] @json = @parent.children @query @index = 0 @has_more = @json["has_more"] else @has_content = false end else @has_content = false end end elsif @database unless @has_content # re-exec unless @load_all_contents @query.start_cursor = nil @json = @nc.database_query_request @database.id, @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 = @nc.database_query_request @database.id, @query @index = 0 @has_more = @json["has_more"] else @has_content = false end else @has_content = false end end elsif @property while @has_content if @index < results.length json = results[@index] object = case json["type"] when "people" UserObject.new json: json["people"] when "relation" json["relation"]["id"] when "rich_text" RichTextObject.create_from_json json["rich_text"] when "title" RichTextObject.create_from_json json["title"] else json end @index += 1 yield object elsif @has_more if @property @query ||= Query.new @query.start_cursor = @json["next_cursor"] @json = NotionCache.instance.page_property_request @property.property_cache.page_id, @property.property_id, @query.query_json @index = 0 @has_more = @json["has_more"] else @has_content = false end else @has_content = false end end end self end |