Class: Tabled
- Inherits:
-
Object
- Object
- Tabled
- Includes:
- BaseFileBuilder
- Defined in:
- lib/tabled.rb,
lib/helpers.rb,
lib/template.rb,
lib/content_shaper.rb,
lib/parsers/csv_parser.rb,
lib/parsers/json_parser.rb
Defined Under Namespace
Classes: CSVParser, ContentShaper, FormatError, Helpers, JSONParser, Template
Constant Summary collapse
- DEFAULT_OPTIONS =
{ framed: true, row_separator: '-', titles: [] }.freeze
Instance Attribute Summary collapse
-
#columns_width ⇒ Object
Returns the value of attribute columns_width.
-
#content ⇒ Object
Returns the value of attribute content.
-
#data ⇒ Object
Returns the value of attribute data.
-
#data_without_options ⇒ Object
Returns the value of attribute data_without_options.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data, **options) ⇒ Tabled
constructor
A new instance of Tabled.
- #print_to_console ⇒ Object
Methods included from BaseFileBuilder
Constructor Details
#initialize(data, **options) ⇒ Tabled
Returns a new instance of Tabled.
15 16 17 18 19 20 |
# File 'lib/tabled.rb', line 15 def initialize(data, **) @options = DEFAULT_OPTIONS.merge() @data = Tabled::Helpers.convert_to_required_structure(data) @columns_width = Tabled::Helpers.calculate_columns_width(data: data, options: @options) @content = Tabled::ContentShaper.new(data, @columns_width, @options).shape end |
Instance Attribute Details
#columns_width ⇒ Object
Returns the value of attribute columns_width.
13 14 15 |
# File 'lib/tabled.rb', line 13 def columns_width @columns_width end |
#content ⇒ Object
Returns the value of attribute content.
13 14 15 |
# File 'lib/tabled.rb', line 13 def content @content end |
#data ⇒ Object
Returns the value of attribute data.
13 14 15 |
# File 'lib/tabled.rb', line 13 def data @data end |
#data_without_options ⇒ Object
Returns the value of attribute data_without_options.
13 14 15 |
# File 'lib/tabled.rb', line 13 def @data_without_options end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/tabled.rb', line 13 def @options end |
Class Method Details
.from_csv(csv:, **options) ⇒ Object
26 27 28 29 30 |
# File 'lib/tabled.rb', line 26 def self.from_csv(csv:, **) raise Tabled::FormatError.new(received_format: csv.class) unless csv.is_a? CSV::Table new(csv.to_a, **) end |
Instance Method Details
#print_to_console ⇒ Object
22 23 24 |
# File 'lib/tabled.rb', line 22 def print_to_console print content.join("\n") end |