Class: Rack::Sparklines::Cachers::Abstract
- Inherits:
-
Object
- Object
- Rack::Sparklines::Cachers::Abstract
- Defined in:
- lib/rack-sparklines/cachers/abstract.rb
Overview
Reads sparkline data from CSV files. Only the first line of numbers are read. Requests for “/sparks/stats.csv” will pass a data_path of “stats.csv”
Direct Known Subclasses
Instance Attribute Summary collapse
-
#png_path ⇒ Object
Returns the value of attribute png_path.
Instance Method Summary collapse
- #create_sparklines(data, options) ⇒ Object
- #exists? ⇒ Boolean
-
#initialize ⇒ Abstract
constructor
A new instance of Abstract.
- #save(data, options) ⇒ Object
- #serve(app, headers = {}) ⇒ Object
-
#set(png_path) ⇒ Object
Setting the png_path returns a duplicate of this object that has any custom instance variables (configuration settings, for example).
- #size ⇒ Object
- #stream ⇒ Object
- #updated_at ⇒ Object
Constructor Details
#initialize ⇒ Abstract
Returns a new instance of Abstract.
11 12 13 |
# File 'lib/rack-sparklines/cachers/abstract.rb', line 11 def initialize @size, @updated_at = nil end |
Instance Attribute Details
#png_path ⇒ Object
Returns the value of attribute png_path.
9 10 11 |
# File 'lib/rack-sparklines/cachers/abstract.rb', line 9 def png_path @png_path end |
Instance Method Details
#create_sparklines(data, options) ⇒ Object
35 36 37 |
# File 'lib/rack-sparklines/cachers/abstract.rb', line 35 def create_sparklines(data, ) Spark.plot(data, ) end |
#exists? ⇒ Boolean
27 28 29 |
# File 'lib/rack-sparklines/cachers/abstract.rb', line 27 def exists? raise NotImplementedError end |
#save(data, options) ⇒ Object
48 49 50 |
# File 'lib/rack-sparklines/cachers/abstract.rb', line 48 def save(data, ) raise NotImplementedError end |
#serve(app, headers = {}) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/rack-sparklines/cachers/abstract.rb', line 39 def serve(app, headers = {}) headers = { "Last-Modified" => updated_at.rfc822, "Content-Type" => "image/png", "Content-Length" => size.to_s }.update(headers) [200, headers, app] end |
#set(png_path) ⇒ Object
Setting the png_path returns a duplicate of this object that has any custom instance variables (configuration settings, for example).
17 18 19 20 21 |
# File 'lib/rack-sparklines/cachers/abstract.rb', line 17 def set(png_path) cacher = dup cacher.png_path = png_path cacher end |
#size ⇒ Object
23 24 25 |
# File 'lib/rack-sparklines/cachers/abstract.rb', line 23 def size raise NotImplementedError end |
#stream ⇒ Object
52 53 54 |
# File 'lib/rack-sparklines/cachers/abstract.rb', line 52 def stream raise NotImplementedError end |
#updated_at ⇒ Object
31 32 33 |
# File 'lib/rack-sparklines/cachers/abstract.rb', line 31 def updated_at raise NotImplementedError end |