Class: Mistri::Usage::Cost
- Inherits:
-
Data
- Object
- Data
- Mistri::Usage::Cost
- Defined in:
- lib/mistri/usage.rb
Overview
Dollar amounts plus whether every contributing token had known pricing. Known stays outside the released Data shape so pattern matching and positional construction remain compatible.
Instance Attribute Summary collapse
-
#cache_read ⇒ Object
readonly
Returns the value of attribute cache_read.
-
#cache_write ⇒ Object
readonly
Returns the value of attribute cache_write.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #_dump(_level) ⇒ Object
- #hash ⇒ Object
-
#initialize(input:, output:, cache_read:, cache_write:, total:, known: true) ⇒ Cost
constructor
A new instance of Cost.
- #known? ⇒ Boolean
- #to_h ⇒ Object
- #with(**changes) ⇒ Object
Constructor Details
#initialize(input:, output:, cache_read:, cache_write:, total:, known: true) ⇒ Cost
Returns a new instance of Cost.
18 19 20 21 |
# File 'lib/mistri/usage.rb', line 18 def initialize(input:, output:, cache_read:, cache_write:, total:, known: true) @known = known == true super(input:, output:, cache_read:, cache_write:, total:) end |
Instance Attribute Details
#cache_read ⇒ Object (readonly)
Returns the value of attribute cache_read
17 18 19 |
# File 'lib/mistri/usage.rb', line 17 def cache_read @cache_read end |
#cache_write ⇒ Object (readonly)
Returns the value of attribute cache_write
17 18 19 |
# File 'lib/mistri/usage.rb', line 17 def cache_write @cache_write end |
#input ⇒ Object (readonly)
Returns the value of attribute input
17 18 19 |
# File 'lib/mistri/usage.rb', line 17 def input @input end |
#output ⇒ Object (readonly)
Returns the value of attribute output
17 18 19 |
# File 'lib/mistri/usage.rb', line 17 def output @output end |
#total ⇒ Object (readonly)
Returns the value of attribute total
17 18 19 |
# File 'lib/mistri/usage.rb', line 17 def total @total end |
Class Method Details
._load(payload) ⇒ Object
56 |
# File 'lib/mistri/usage.rb', line 56 def self._load(payload) = new(**JSON.parse(payload, symbolize_names: true)) |
.unknown ⇒ Object
28 29 30 31 |
# File 'lib/mistri/usage.rb', line 28 def self.unknown new(input: 0.0, output: 0.0, cache_read: 0.0, cache_write: 0.0, total: 0.0, known: false) end |
.zero ⇒ Object
23 24 25 26 |
# File 'lib/mistri/usage.rb', line 23 def self.zero new(input: 0.0, output: 0.0, cache_read: 0.0, cache_write: 0.0, total: 0.0, known: true) end |
Instance Method Details
#+(other) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/mistri/usage.rb', line 39 def +(other) self.class.new(input: input + other.input, output: output + other.output, cache_read: cache_read + other.cache_read, cache_write: cache_write + other.cache_write, total: total + other.total, known: known? && other.known?) end |
#==(other) ⇒ Object Also known as: eql?
46 |
# File 'lib/mistri/usage.rb', line 46 def ==(other) = super && known? == other.known? |
#_dump(_level) ⇒ Object
54 |
# File 'lib/mistri/usage.rb', line 54 def _dump(_level) = JSON.generate(to_h) |
#hash ⇒ Object
50 |
# File 'lib/mistri/usage.rb', line 50 def hash = [super, known?].hash |
#known? ⇒ Boolean
33 |
# File 'lib/mistri/usage.rb', line 33 def known? = defined?(@known) ? @known : true |
#to_h ⇒ Object
52 |
# File 'lib/mistri/usage.rb', line 52 def to_h = super.merge(known: known?) |
#with(**changes) ⇒ Object
35 36 37 |
# File 'lib/mistri/usage.rb', line 35 def with(**changes) self.class.new(**to_h, **changes) end |