Class: Sheets::Base
- Inherits:
-
Object
- Object
- Sheets::Base
- Includes:
- Parseable, Renderable
- Defined in:
- lib/sheets/base.rb
Instance Method Summary collapse
- #default_to_array ⇒ Object
-
#initialize(file, options = {}) ⇒ Base
constructor
A new instance of Base.
- #to_array ⇒ Object
Methods included from Renderable
Methods included from Parseable
Constructor Details
#initialize(file, options = {}) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sheets/base.rb', line 6 def initialize(file, = {}) if file.is_a?(Array) @data = file @extension = [:format].to_s return end file = File.open(file.to_s) unless file.respond_to? :read [:format] ||= File.basename(file.path || "").split('.')[-1] @data = file.read @extension = [:format].to_s @file_path = File.(file.path || "") raise UnsupportedSpreadsheetFormatError, "Couldn't find a parser for the '#{@extension}' format." if parser.nil? end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Sheets::Renderable
Instance Method Details
#default_to_array ⇒ Object
23 |
# File 'lib/sheets/base.rb', line 23 alias_method :default_to_array, :to_array |
#to_array ⇒ Object
24 25 26 |
# File 'lib/sheets/base.rb', line 24 def to_array @data.is_a?(Array) ? @data : default_to_array end |