Class: Sanity::Groq::Slice

Inherits:
Object
  • Object
show all
Defined in:
lib/sanity/groq/slice.rb

Constant Summary collapse

RESERVED =
%i[limit offset]
ZERO_INDEX =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Slice

Returns a new instance of Slice.



17
18
19
20
21
22
# File 'lib/sanity/groq/slice.rb', line 17

def initialize(**args)
  args.slice(*RESERVED).then do |opts|
    @limit = opts[:limit]
    @offset = opts[:offset]
  end
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



15
16
17
# File 'lib/sanity/groq/slice.rb', line 15

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



15
16
17
# File 'lib/sanity/groq/slice.rb', line 15

def offset
  @offset
end

Class Method Details

.call(**args) ⇒ Object



7
8
9
# File 'lib/sanity/groq/slice.rb', line 7

def call(**args)
  new(**args).call
end

Instance Method Details

#callObject



24
25
26
27
28
# File 'lib/sanity/groq/slice.rb', line 24

def call
  return "" unless limit

  (!offset) ? zero_index_to_limit : offset_to_limit
end