Class: Sanity::Groq::Select

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

Constant Summary collapse

RESERVED =
%i[select]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Select

Returns a new instance of Select.



18
19
20
21
22
23
24
# File 'lib/sanity/groq/select.rb', line 18

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

  @val = +""
end

Instance Attribute Details

#selectObject (readonly)

Returns the value of attribute select.



16
17
18
# File 'lib/sanity/groq/select.rb', line 16

def select
  @select
end

#valObject (readonly)

Returns the value of attribute val.



16
17
18
# File 'lib/sanity/groq/select.rb', line 16

def val
  @val
end

Class Method Details

.call(**args) ⇒ Object



9
10
11
# File 'lib/sanity/groq/select.rb', line 9

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

Instance Method Details

#callObject



26
27
28
29
30
31
32
33
34
# File 'lib/sanity/groq/select.rb', line 26

def call
  return unless select

  Array.wrap(select).each_with_index do |x, idx|
    val << "#{idx.positive? ? "," : ""} #{x}"
  end

  "{ #{val.strip} }"
end