Class: Checkoff::Internal::SearchUrl::SimpleParam::SimpleParam
- Inherits:
-
Object
- Object
- Checkoff::Internal::SearchUrl::SimpleParam::SimpleParam
- 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
Direct Known Subclasses
AllTagsIds, AnyProjectsIds, AnyTagsIds, Approval, Completion, LocatedIn, Milestone, NotProjectsIds, NotTagsIds, PortfoliosIds, SearchedType, Sort, Subtask
Instance Attribute Summary collapse
- #key ⇒ String readonly
- #values ⇒ Array<String> readonly
Instance Method Summary collapse
-
#convert_from_projects_and_sections(verb) ⇒ ::Array[String]
@param
verb. -
#initialize(key:, values:) ⇒ SimpleParam
constructor
@param
key— the name of the search url param. -
#parse_projects_and_sections(projects, sections) ⇒ void
Inputs: 123_column_456 means "abc" project, "def" section 123 means "abc" project 123~456 means "abc" and "def" projects.
-
#single_value ⇒ String
@return — the single value of the search url param.
Constructor Details
#initialize(key:, values:) ⇒ SimpleParam
@param key — the name of the search url param
@param values — the values of the search url param
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
#key ⇒ String (readonly)
35 36 37 |
# File 'lib/checkoff/internal/search_url/simple_param_converter.rb', line 35 def key @key end |
#values ⇒ Array<String> (readonly)
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
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
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_value ⇒ String
@return — the single value of the search url param
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 |