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])]])


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

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])]])


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

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
# File 'lib/checkoff/internal/search_url/parser.rb', line 26

def convert_params(url)
  # @sg-ignore
  url_params = CGI.parse(URI.parse(url).query)
  # @sg-ignore
  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])


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

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, String])

Returns:

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


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

def partition_url_params(url_params)
  groups = T.let(url_params.to_a.group_by do |key, _values|
                   # @sg-ignore
                   if key.start_with? 'custom_field_'
                     :custom_field
                   # @sg-ignore
                   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