Class: NotionRubyMapping::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/notion_ruby_mapping/query.rb

Overview

Query object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filter: {}, sort: []) ⇒ Query



6
7
8
9
# File 'lib/notion_ruby_mapping/query.rb', line 6

def initialize(filter: {}, sort: [])
  @filter = filter
  @sort = sort
end

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter.



10
11
12
# File 'lib/notion_ruby_mapping/query.rb', line 10

def filter
  @filter
end

#sortObject (readonly)

Returns the value of attribute sort.



10
11
12
# File 'lib/notion_ruby_mapping/query.rb', line 10

def sort
  @sort
end

Instance Method Details

#and(other_query) ⇒ NotionRubyMapping::Query



14
15
16
17
18
19
20
21
# File 'lib/notion_ruby_mapping/query.rb', line 14

def and(other_query)
  if @filter.key? "and"
    @filter["and"] << other_query.filter
  else
    @filter = {"and" => [@filter, other_query.filter]}
  end
  self
end

#ascending(property) ⇒ NotionRubyMapping::Query



36
37
38
39
40
# File 'lib/notion_ruby_mapping/query.rb', line 36

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



44
45
46
47
48
# File 'lib/notion_ruby_mapping/query.rb', line 44

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



25
26
27
28
29
30
31
32
# File 'lib/notion_ruby_mapping/query.rb', line 25

def or(other_query)
  if @filter.key? "or"
    @filter["or"] << other_query.filter
  else
    @filter = {"or" => [@filter, other_query.filter]}
  end
  self
end