Class: Checkoff::Internal::SearchUrl::CustomFieldVariant::CustomFieldVariant

Inherits:
Object
  • Object
show all
Defined in:
lib/checkoff/internal/search_url/custom_field_variant.rb,
sig/checkoff.rbs

Overview

base class for handling different custom_field_##gid.variant params

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gid, remaining_params) ⇒ CustomFieldVariant

@param gid

@param remaining_params

Parameters:

  • gid (String)
  • remaining_params (::Hash[String, ::Array[String]])


13
14
15
16
# File 'lib/checkoff/internal/search_url/custom_field_variant.rb', line 13

def initialize(gid, remaining_params)
  @gid = T.let(gid, String)
  @remaining_params = T.let(remaining_params, T::Hash[String, T::Array[String]])
end

Instance Attribute Details

#gidString (readonly)

Returns:

  • (String)


28
29
30
# File 'lib/checkoff/internal/search_url/custom_field_variant.rb', line 28

def gid
  @gid
end

#remaining_paramsHash{String => Array<String>} (readonly)

Returns:

  • (Hash{String => Array<String>})


31
32
33
# File 'lib/checkoff/internal/search_url/custom_field_variant.rb', line 31

def remaining_params
  @remaining_params
end

Instance Method Details

#convert[::Hash[String, String], ::Array[(Symbol | ::Array[untyped])]]

Implemented by every subclass.

Returns:

  • ([::Hash[String, String], ::Array[(Symbol | ::Array[untyped])]])


21
22
23
# File 'lib/checkoff/internal/search_url/custom_field_variant.rb', line 21

def convert
  raise NotImplementedError
end

#ensure_no_remaining_params!void

This method returns an undefined value.



34
35
36
37
38
# File 'lib/checkoff/internal/search_url/custom_field_variant.rb', line 34

def ensure_no_remaining_params!
  return if remaining_params.empty?

  raise "Teach me how to handle these remaining keys: #{remaining_params}"
end

#fetch_solo_param(param_name) ⇒ String

@param param_name

Parameters:

  • param_name (String)

Returns:

  • (String)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/checkoff/internal/search_url/custom_field_variant.rb', line 43

def fetch_solo_param(param_name)
  case remaining_params.keys
  when [param_name]
    # @type param_values [Array<String>]
    param_values = remaining_params.fetch(param_name)
    unless param_values.length == 1
      raise "Teach me how to handle these remaining keys for #{param_name}: #{remaining_params}"
    end

    param_values.fetch(0)
  else
    raise "Teach me how to handle #{remaining_params}"
  end
end