Class: Checkoff::Internal::SearchUrl::CustomFieldParamConverter
- Inherits:
-
Object
- Object
- Checkoff::Internal::SearchUrl::CustomFieldParamConverter
- Defined in:
- lib/checkoff/internal/search_url/custom_field_param_converter.rb,
sig/checkoff.rbs
Overview
Convert custom field parameters from an Asana search URL into API search arguments and Checkoff task selectors
Constant Summary collapse
- VARIANTS =
{ 'is' => CustomFieldVariant::Is, 'no_value' => CustomFieldVariant::NoValue, 'any_value' => CustomFieldVariant::AnyValue, 'is_not' => CustomFieldVariant::IsNot, 'less_than' => CustomFieldVariant::LessThan, 'greater_than' => CustomFieldVariant::GreaterThan, 'equals' => CustomFieldVariant::Equals, 'doesnt_contain_any' => CustomFieldVariant::DoesntContainAny, 'contains_any' => CustomFieldVariant::ContainsAny, 'contains_all' => CustomFieldVariant::ContainsAll, }.freeze
Instance Attribute Summary collapse
Instance Method Summary collapse
- #by_custom_field ⇒ Hash{String => Hash}
- #convert ⇒ Array(Hash{String => String}, Array<Symbol, Array>)
-
#convert_single_custom_field_params(gid, single_custom_field_params) ⇒ [::Hash[String, String], ::Array[(Symbol | ::Array[untyped])]]
@sg-ignore.
-
#gid_from_custom_field_key(key) ⇒ String
@sg-ignore.
-
#initialize(custom_field_params:) ⇒ CustomFieldParamConverter
constructor
@param
custom_field_params.
Constructor Details
#initialize(custom_field_params:) ⇒ CustomFieldParamConverter
@param custom_field_params
14 15 16 |
# File 'lib/checkoff/internal/search_url/custom_field_param_converter.rb', line 14 def initialize(custom_field_params:) @custom_field_params = custom_field_params end |
Instance Attribute Details
#custom_field_params ⇒ Hash{String => Array<String>} (readonly)
89 90 91 |
# File 'lib/checkoff/internal/search_url/custom_field_param_converter.rb', line 89 def custom_field_params @custom_field_params end |
Instance Method Details
#by_custom_field ⇒ Hash{String => Hash}
38 39 40 41 42 |
# File 'lib/checkoff/internal/search_url/custom_field_param_converter.rb', line 38 def by_custom_field custom_field_params.group_by do |key, _value| gid_from_custom_field_key(key) end.transform_values(&:to_h) end |
#convert ⇒ Array(Hash{String => String}, Array<Symbol, Array>)
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/checkoff/internal/search_url/custom_field_param_converter.rb', line 19 def convert # @type args [Hash{String => String}] args = {} # @type task_selector [Array<Symbol, Array>] task_selector = [] by_custom_field.each do |gid, single_custom_field_params| new_args, new_task_selector = convert_single_custom_field_params(gid, single_custom_field_params) args = ResultsMerger.merge_args(args, new_args) task_selector = ResultsMerger.merge_task_selectors(task_selector, new_task_selector) end [args, task_selector] end |
#convert_single_custom_field_params(gid, single_custom_field_params) ⇒ [::Hash[String, String], ::Array[(Symbol | ::Array[untyped])]]
@sg-ignore
@param gid
@param single_custom_field_params
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/checkoff/internal/search_url/custom_field_param_converter.rb', line 63 def convert_single_custom_field_params(gid, single_custom_field_params) variant_key = "custom_field_#{gid}.variant" variant = single_custom_field_params.fetch(variant_key) remaining_params = single_custom_field_params.reject { |k, _v| k == variant_key } raise "Teach me how to handle #{variant_key} = #{variant}" unless variant.length == 1 # @sg-ignore # @type [Class<CustomFieldVariant>] # @sg-ignore variant_class = VARIANTS[variant[0]] # @type [Array(Hash{String => String}, Array<Symbol, Array>)] # @sg-ignore return variant_class.new(gid, remaining_params).convert unless variant_class.nil? raise "Teach me how to handle #{variant_key} = #{variant}" end |
#gid_from_custom_field_key(key) ⇒ String
@sg-ignore
@param key
83 84 85 86 |
# File 'lib/checkoff/internal/search_url/custom_field_param_converter.rb', line 83 def gid_from_custom_field_key(key) # @sg-ignore key.split('_')[2].split('.')[0] end |