Class: Sox::Stats::Cache
- Inherits:
-
Object
- Object
- Sox::Stats::Cache
- Defined in:
- lib/sox/stats.rb
Instance Attribute Summary collapse
-
#sound_file ⇒ Object
Returns the value of attribute sound_file.
Instance Method Summary collapse
- #cache_file ⇒ Object
- #dump(attributes) ⇒ Object
- #fetch(&block) ⇒ Object
-
#initialize(sound_file) ⇒ Cache
constructor
A new instance of Cache.
- #load ⇒ Object
Constructor Details
#initialize(sound_file) ⇒ Cache
Returns a new instance of Cache.
33 34 35 |
# File 'lib/sox/stats.rb', line 33 def initialize(sound_file) @sound_file = sound_file end |
Instance Attribute Details
#sound_file ⇒ Object
Returns the value of attribute sound_file.
31 32 33 |
# File 'lib/sox/stats.rb', line 31 def sound_file @sound_file end |
Instance Method Details
#cache_file ⇒ Object
37 38 39 |
# File 'lib/sox/stats.rb', line 37 def cache_file "#{sound_file}.stats" end |
#dump(attributes) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/sox/stats.rb', line 45 def dump(attributes) File.open(cache_file, "w") do |f| f.write YAML.dump(attributes) end attributes end |
#fetch(&block) ⇒ Object
52 53 54 |
# File 'lib/sox/stats.rb', line 52 def fetch(&block) load or dump(block.call) end |
#load ⇒ Object
41 42 43 |
# File 'lib/sox/stats.rb', line 41 def load YAML.load(IO.read(cache_file)) rescue nil end |