Class: Measured::ConversionTableBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/measured/conversion_table_builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#unitsObject (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

Returns:

  • (Boolean)


20
21
22
# File 'lib/measured/conversion_table_builder.rb', line 20

def cached?
  @cache.exist?
end

#to_hObject



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_cacheObject



16
17
18
# File 'lib/measured/conversion_table_builder.rb', line 16

def update_cache
  @cache.write(generate_table)
end