lib/tabled.rb in tabled-1.1.0 vs lib/tabled.rb in tabled-1.2.0
- old
+ new
@@ -2,10 +2,11 @@
require_relative 'template'
require_relative 'helpers'
require_relative 'content_shaper'
require_relative 'file_builders/base_file_builder'
+require_relative 'errors/format_error'
class Tabled
include BaseFileBuilder
DEFAULT_OPTIONS = { framed: true, row_separator: '-', titles: [] }.freeze
@@ -18,7 +19,13 @@
@content = Tabled::ContentShaper.new(data, @columns_width, @options).shape
end
def print_to_console
print content.join("\n")
+ end
+
+ def self.from_csv(csv:, **options)
+ raise Tabled::FormatError.new(received_format: csv.class) unless csv.is_a? CSV::Table
+
+ new(csv.to_a, **options)
end
end