Class: RubyLLM::Model::PricingTier

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/model/pricing_tier.rb

Overview

A dynamic class for storing non-zero pricing values with flexible attribute access

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ PricingTier

Returns a new instance of PricingTier.



7
8
9
10
11
12
13
# File 'lib/ruby_llm/model/pricing_tier.rb', line 7

def initialize(data = {})
  @values = {}

  data.each do |key, value|
    @values[key.to_sym] = value if value && value != 0.0
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/ruby_llm/model/pricing_tier.rb', line 15

def method_missing(method, *args)
  if method.to_s.end_with?('=')
    key = method.to_s.chomp('=').to_sym
    @values[key] = args.first if args.first && args.first != 0.0
  elsif @values.key?(method)
    @values[method]
  end
end

Instance Method Details

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/ruby_llm/model/pricing_tier.rb', line 24

def respond_to_missing?(method, include_private = false)
  method.to_s.end_with?('=') || @values.key?(method.to_sym) || super
end

#to_hObject



28
29
30
# File 'lib/ruby_llm/model/pricing_tier.rb', line 28

def to_h
  @values
end