class Sanity::Groq::Slice

Constants

RESERVED
ZERO_INDEX

Attributes

limit[R]
offset[R]

Public Class Methods

call(**args) click to toggle source
# File lib/sanity/groq/slice.rb, line 7
def call(**args)
  new(**args).call
end
new(**args) click to toggle source
# 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

Public Instance Methods

call() click to toggle source
# File lib/sanity/groq/slice.rb, line 24
def call
  return "" unless limit

  !offset ? zero_index_to_limit : offset_to_limit
end

Private Instance Methods

offset_to_limit() click to toggle source
# File lib/sanity/groq/slice.rb, line 32
def offset_to_limit
  "[#{offset}...#{limit + offset}]"
end
zero_index_to_limit() click to toggle source
# File lib/sanity/groq/slice.rb, line 36
def zero_index_to_limit
  "[#{ZERO_INDEX}...#{limit}]"
end