Sha256: c13b2bf2025b04655b60035d77f5139435b8970d5beb5ee4385d65975d9b7170
Contents?: true
Size: 737 Bytes
Versions: 2
Compression:
Stored size: 737 Bytes
Contents
require 'rack-sparklines/handlers/abstract_data' module Rack::Sparklines::Handlers # 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" class CsvData < AbstractData attr_accessor :directory def initialize(directory) @directory = directory end def data_path=(s) @data_path = s ? File.join(@directory, s) : nil end def exists? File.exist?(@data_path) end def updated_at File.mtime(@data_path) end def fetch array_of_nums = IO.read(@data_path).split("\n").first.split(",") array_of_nums.map! { |n| n.to_i } yield array_of_nums end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rack-sparklines-1.1.0 | lib/rack-sparklines/handlers/csv_data.rb |
rack-sparklines-1.0.0 | lib/rack-sparklines/handlers/csv_data.rb |