Class: Legion::Extensions::Llm::Model::PricingTier
- Inherits:
-
Object
- Object
- Legion::Extensions::Llm::Model::PricingTier
- Defined in:
- lib/legion/extensions/llm/model/pricing_tier.rb
Overview
A dynamic class for storing non-zero pricing values with flexible attribute access
Instance Method Summary collapse
-
#initialize(data = {}) ⇒ PricingTier
constructor
A new instance of PricingTier.
- #method_missing(method, *args) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ PricingTier
Returns a new instance of PricingTier.
9 10 11 12 13 14 15 |
# File 'lib/legion/extensions/llm/model/pricing_tier.rb', line 9 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
17 18 19 20 21 22 23 24 |
# File 'lib/legion/extensions/llm/model/pricing_tier.rb', line 17 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
26 27 28 |
# File 'lib/legion/extensions/llm/model/pricing_tier.rb', line 26 def respond_to_missing?(method, include_private = false) method.to_s.end_with?('=') || @values.key?(method.to_sym) || super end |
#to_h ⇒ Object
30 31 32 |
# File 'lib/legion/extensions/llm/model/pricing_tier.rb', line 30 def to_h @values end |