Class: NotionRubyMapping::Query
- Inherits:
-
Object
- Object
- NotionRubyMapping::Query
- Defined in:
- lib/notion_ruby_mapping/controllers/query.rb
Overview
Query object
Instance Attribute Summary collapse
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
-
#sort ⇒ Object
readonly
Returns the value of attribute sort.
-
#start_cursor ⇒ Object
Returns the value of attribute start_cursor.
Instance Method Summary collapse
-
#and(another_query) ⇒ NotionRubyMapping::Query
Updated self (Query object).
-
#ascending(property) ⇒ NotionRubyMapping::Query
Updated self (Query object).
-
#descending(property) ⇒ NotionRubyMapping::Query
Updated self (Query object).
-
#initialize(filter: {}, sort: [], page_size: 100, start_cursor: nil) ⇒ Query
constructor
A new instance of Query.
-
#or(other_query) ⇒ NotionRubyMapping::Query
Updated self (Query object).
- #query_json ⇒ Hash
- #query_string ⇒ String (frozen)
Constructor Details
#initialize(filter: {}, sort: [], page_size: 100, start_cursor: nil) ⇒ Query
6 7 8 9 10 11 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 6 def initialize(filter: {}, sort: [], page_size: 100, start_cursor: nil) @filter = filter @sort = sort @page_size = page_size @start_cursor = start_cursor end |
Instance Attribute Details
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
12 13 14 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 12 def filter @filter end |
#page_size ⇒ Object (readonly)
Returns the value of attribute page_size.
12 13 14 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 12 def page_size @page_size end |
#sort ⇒ Object (readonly)
Returns the value of attribute sort.
12 13 14 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 12 def sort @sort end |
#start_cursor ⇒ Object
Returns the value of attribute start_cursor.
13 14 15 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 13 def start_cursor @start_cursor end |
Instance Method Details
#and(another_query) ⇒ NotionRubyMapping::Query
17 18 19 20 21 22 23 24 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 17 def and(another_query) if @filter.key? "and" @filter["and"] << another_query.filter else @filter = {"and" => [@filter, another_query.filter]} end self end |
#ascending(property) ⇒ NotionRubyMapping::Query
28 29 30 31 32 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 28 def ascending(property) key = property.is_a?(LastEditedTimeProperty) || property.is_a?(CreatedTimeProperty) ? "timestamp" : "property" @sort << {key => property.name, "direction" => "ascending"} self end |
#descending(property) ⇒ NotionRubyMapping::Query
36 37 38 39 40 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 36 def descending(property) key = property.is_a?(LastEditedTimeProperty) || property.is_a?(CreatedTimeProperty) ? "timestamp" : "property" @sort << {key => property.name, "direction" => "descending"} self end |
#or(other_query) ⇒ NotionRubyMapping::Query
44 45 46 47 48 49 50 51 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 44 def or(other_query) if @filter.key? "or" @filter["or"] << other_query.filter else @filter = {"or" => [@filter, other_query.filter]} end self end |
#query_json ⇒ Hash
54 55 56 57 58 59 60 61 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 54 def query_json parameters = {} parameters[:filter] = @filter unless @filter.empty? parameters[:sorts] = @sort unless @sort.empty? parameters[:start_cursor] = @start_cursor if @start_cursor parameters[:page_size] = @page_size if @page_size parameters end |
#query_string ⇒ String (frozen)
64 65 66 67 68 69 |
# File 'lib/notion_ruby_mapping/controllers/query.rb', line 64 def query_string ans = [] ans << "page_size=#{@page_size}" if @page_size ans << "start_cursor=#{@start_cursor}" if @start_cursor ans.empty? ? "" : "?#{ans.join("&")}" end |