Class: Measured::ConversionTableBuilder
- Inherits:
-
Object
- Object
- Measured::ConversionTableBuilder
- Defined in:
- lib/measured/conversion_table_builder.rb
Instance Attribute Summary collapse
-
#units ⇒ Object
readonly
Returns the value of attribute units.
Instance Method Summary collapse
- #cached? ⇒ Boolean
-
#initialize(units, cache: nil) ⇒ ConversionTableBuilder
constructor
A new instance of ConversionTableBuilder.
- #to_h ⇒ Object
- #update_cache ⇒ Object
Constructor Details
#initialize(units, cache: nil) ⇒ ConversionTableBuilder
Returns a new instance of ConversionTableBuilder.
5 6 7 8 9 |
# File 'lib/measured/conversion_table_builder.rb', line 5 def initialize(units, cache: nil) @units = units cache ||= { class: Measured::Cache::Null } @cache = cache[:class].new(*cache[:args]) end |
Instance Attribute Details
#units ⇒ Object (readonly)
Returns the value of attribute units.
3 4 5 |
# File 'lib/measured/conversion_table_builder.rb', line 3 def units @units end |
Instance Method Details
#cached? ⇒ Boolean
20 21 22 |
# File 'lib/measured/conversion_table_builder.rb', line 20 def cached? @cache.exist? end |
#to_h ⇒ Object
11 12 13 14 |
# File 'lib/measured/conversion_table_builder.rb', line 11 def to_h return @cache.read if cached? generate_table end |
#update_cache ⇒ Object
16 17 18 |
# File 'lib/measured/conversion_table_builder.rb', line 16 def update_cache @cache.write(generate_table) end |