Class: Checkoff::Internal::SearchUrl::Parser

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

Overview

Parse Asana search URLs into parameters suitable to pass into the /workspaces/workspace_gid/tasks/search endpoint

Instance Method Summary collapse

Constructor Details

#initialize(_deps = {}) ⇒ Parser

@param _deps

Parameters:

  • _deps (::Hash[untyped, untyped]) (defaults to: {})


20
21
22
# File 'lib/checkoff/internal/search_url/parser.rb', line 20

def initialize(_deps = {})
  # allow dependencies to be passed in by tests
end

Instance Method Details

#convert_custom_field_params(custom_field_params) ⇒ [::Hash[String, String], ::Array[(Symbol | ::Array[untyped])]]

@param custom_field_params

Parameters:

  • custom_field_params (::Hash[String, ::Array[String]])

Returns:

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


56
57
58
# File 'lib/checkoff/internal/search_url/parser.rb', line 56

def convert_custom_field_params(custom_field_params)
  CustomFieldParamConverter.new(custom_field_params:).convert
end

#convert_date_params(date_url_params) ⇒ [::Hash[String, String], ::Array[(Symbol | ::Array[untyped])]]

@param date_url_params

Parameters:

  • date_url_params (::Hash[String, ::Array[String]])

Returns:

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


44
45
46
# File 'lib/checkoff/internal/search_url/parser.rb', line 44

def convert_date_params(date_url_params)
  DateParamConverter.new(date_url_params:).convert
end

#convert_params(url) ⇒ [::Hash[String, String], ::Array[untyped]]

@param url

Parameters:

  • url (String)

Returns:

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


26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/checkoff/internal/search_url/parser.rb', line 26

def convert_params(url)
  # @sg-ignore URI#query can be nil for a URL with no query string; CGI.parse expects
  #   String — looks like a real gap (unhandled no-query-string case), not just a typing
  #   gap, flagging for the follow-up code PR rather than silently asserting non-nil
  url_params = CGI.parse(URI.parse(url).query)
  custom_field_params, date_url_params, simple_url_params = partition_url_params(url_params)
  custom_field_args, custom_field_task_selector = convert_custom_field_params(custom_field_params)
  date_url_args, date_task_selector = convert_date_params(date_url_params)
  simple_url_args = convert_simple_params(simple_url_params)
  # raise 'merge these things'
  [ResultsMerger.merge_args(custom_field_args, date_url_args, simple_url_args),
   ResultsMerger.merge_task_selectors(date_task_selector, custom_field_task_selector)]
end

#convert_simple_params(simple_url_params) ⇒ ::Hash[String, String]

@param simple_url_params

Parameters:

  • simple_url_params (::Hash[String, ::Array[String]])

Returns:

  • (::Hash[String, String])


50
51
52
# File 'lib/checkoff/internal/search_url/parser.rb', line 50

def convert_simple_params(simple_url_params)
  SimpleParamConverter.new(simple_url_params:).convert
end

#partition_url_params(url_params) ⇒ [::Hash[String, ::Array[String]], ::Hash[String, ::Array[String]], ::Hash[String, ::Array[String]]]

@param url_params

Parameters:

  • url_params (::Hash[String, ::Array[String]])

Returns:

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


62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/checkoff/internal/search_url/parser.rb', line 62

def partition_url_params(url_params)
  groups = T.let(url_params.to_a.group_by do |key, _values|
                   # @sg-ignore Unresolved call to start_with? — T.let wrapping this
                   #   chained group_by block seems to block block-param inference
                   if key.start_with? 'custom_field_'
                     :custom_field
                   # @sg-ignore Unresolved call to include? — same T.let/block-param gap
                   elsif key.include? '_date'
                     :date
                   else
                     :simple
                   end
                 end.transform_values(&:to_h),
                 T::Hash[Symbol, T::Hash[String, T::Array[String]]])
  [groups.fetch(:custom_field, {}), groups.fetch(:date, {}), groups.fetch(:simple, {})]
end