Class: Rack::Sparklines::Handlers::StubbedData
- Inherits:
-
AbstractData
- Object
- AbstractData
- Rack::Sparklines::Handlers::StubbedData
- Defined in:
- lib/rack-sparklines/handlers/stubbed_data.rb
Overview
Allows you to stub sparkline data in a global hash. Requests for “/sparks/stats.csv” will pass a data_path of “stats.csv”
Instance Attribute Summary collapse
-
#datasets ⇒ Object
A hash of hashes where the key is the filename.
Attributes inherited from AbstractData
Instance Method Summary collapse
- #data_path=(s) ⇒ Object
- #exists? ⇒ Boolean
- #fetch {|@data[:contents]| ... } ⇒ Object
-
#initialize(datasets = {}) ⇒ StubbedData
constructor
A new instance of StubbedData.
- #updated_at ⇒ Object
Methods inherited from AbstractData
Constructor Details
#initialize(datasets = {}) ⇒ StubbedData
Returns a new instance of StubbedData.
15 16 17 |
# File 'lib/rack-sparklines/handlers/stubbed_data.rb', line 15 def initialize(datasets = {}) @datasets = datasets end |
Instance Attribute Details
#datasets ⇒ Object
A hash of hashes where the key is the filename. The key points to a hash with :updated and :contents keys
StubbedData.datasets['stats.csv'] = {
:updated => Time.utc(2009, 10, 1),
:contents => [1, 2, 3, 4, 5]}
13 14 15 |
# File 'lib/rack-sparklines/handlers/stubbed_data.rb', line 13 def datasets @datasets end |
Instance Method Details
#data_path=(s) ⇒ Object
19 20 21 22 |
# File 'lib/rack-sparklines/handlers/stubbed_data.rb', line 19 def data_path=(s) @data = @datasets[s] @data_path = s end |
#exists? ⇒ Boolean
24 25 26 |
# File 'lib/rack-sparklines/handlers/stubbed_data.rb', line 24 def exists? @data end |
#fetch {|@data[:contents]| ... } ⇒ Object
32 33 34 |
# File 'lib/rack-sparklines/handlers/stubbed_data.rb', line 32 def fetch yield @data[:contents] if @data end |
#updated_at ⇒ Object
28 29 30 |
# File 'lib/rack-sparklines/handlers/stubbed_data.rb', line 28 def updated_at @data[:updated] end |