Class: Checkoff::Internal::SearchUrl::SimpleParam::SimpleParam

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

Overview

base class for handling different types of search url params

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, values:) ⇒ SimpleParam

@param key — the name of the search url param

@param values — the values of the search url param

Parameters:

  • key: (String)
  • values: (::Array[String])


17
18
19
20
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 17

def initialize(key:, values:)
  @key = key
  @values = values
end

Instance Attribute Details

#keyString (readonly)

Returns:

  • (String)


35
36
37
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 35

def key
  @key
end

#valuesArray<String> (readonly)

Returns:

  • (Array<String>)


38
39
40
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 38

def values
  @values
end

Instance Method Details

#convert_from_projects_and_sections(verb) ⇒ ::Array[String]

@param verb

Parameters:

  • verb (String)

Returns:

  • (::Array[String])


63
64
65
66
67
68
69
70
71
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 63

def convert_from_projects_and_sections(verb)
  projects = []
  sections = []
  parse_projects_and_sections(projects, sections)
  out = {}
  out["projects.#{verb}"] = projects.join(',') unless projects.empty?
  out["sections.#{verb}"] = sections.join(',') unless sections.empty?
  out.to_a.flatten
end

#parse_projects_and_sections(projects, sections) ⇒ void

This method returns an undefined value.

Inputs:

123_column_456 means "abc" project, "def" section
123 means "abc" project
123~456 means "abc" and "def" projects

@param projects

@param sections

Parameters:

  • projects (::Array[String])
  • sections (::Array[String])


48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 48

def parse_projects_and_sections(projects, sections)
  single_value.split('~').each do |project_section_pair|
    project, section = project_section_pair.split('_column_')
    raise "Invalid query string: #{project_section_pair}" if project.nil?

    if section.nil?
      projects << project
    else
      sections << section
    end
  end
end

#single_valueString

@return — the single value of the search url param

Returns:

  • (String)


25
26
27
28
29
30
31
32
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 25

def single_value
  @single_value ||= begin
    raise "Teach me how to handle #{key} = #{values}" if values.length != 1

    # @type [String]
    values.fetch(0)
  end
end