Class: LlmCostTracker::Charges::Cost
- Inherits:
-
Data
- Object
- Data
- LlmCostTracker::Charges::Cost
- Defined in:
- lib/llm_cost_tracker/charges/cost.rb
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components
7 8 9 |
# File 'lib/llm_cost_tracker/charges/cost.rb', line 7 def components @components end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency
7 8 9 |
# File 'lib/llm_cost_tracker/charges/cost.rb', line 7 def currency @currency end |
#total ⇒ Object (readonly)
Returns the value of attribute total
7 8 9 |
# File 'lib/llm_cost_tracker/charges/cost.rb', line 7 def total @total end |
Class Method Details
.from_h(attributes) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/llm_cost_tracker/charges/cost.rb', line 8 def self.from_h(attributes) components = attributes.key?(:components) ? attributes[:components] : attributes.except(:total_cost, :currency) total = attributes.fetch(:total) { attributes[:total_cost] } new( components: components.transform_values { |value| BigDecimal(value.to_s) }.freeze, total: total && BigDecimal(total.to_s), currency: attributes[:currency] ) end |
Instance Method Details
#to_h ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/llm_cost_tracker/charges/cost.rb', line 18 def to_h { components: components.transform_values { |value| value.to_s("F") }, total: total&.to_s("F"), currency: currency } end |