Module: LlmCostTracker::Dashboard::Params

Defined in:
app/services/llm_cost_tracker/dashboard/params.rb

Class Method Summary collapse

Class Method Details

.tag_query(value) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'app/services/llm_cost_tracker/dashboard/params.rb', line 20

def tag_query(value)
  to_hash(value).each_with_object({}) do |(key, tag_value), tags|
    key = key.to_s
    tag_value = tag_value.to_s
    next if key.blank? || tag_value.blank?

    tags[key] = tag_value
  end
end

.to_hash(value) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/services/llm_cost_tracker/dashboard/params.rb', line 7

def to_hash(value)
  return {} if value.nil?

  unsafe_hash = value.try(:to_unsafe_h)
  return unsafe_hash if unsafe_hash.is_a?(Hash)
  return value if value.is_a?(Hash)

  hash = value.try(:to_h)
  hash.is_a?(Hash) ? hash : {}
rescue ArgumentError, TypeError
  {}
end