Class: Tabled

Inherits:
Object
  • Object
show all
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, Helpers, JSONParser, Template

Constant Summary collapse

DEFAULT_OPTIONS =
{ framed: true, row_separator: '-', titles: [] }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BaseFileBuilder

#export_to_file

Constructor Details

#initialize(data, **options) ⇒ Tabled

Returns a new instance of Tabled.



14
15
16
17
18
19
# File 'lib/tabled.rb', line 14

def initialize(data, **options)
  @options = DEFAULT_OPTIONS.merge(options)
  @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_widthObject

Returns the value of attribute columns_width.



12
13
14
# File 'lib/tabled.rb', line 12

def columns_width
  @columns_width
end

#contentObject

Returns the value of attribute content.



12
13
14
# File 'lib/tabled.rb', line 12

def content
  @content
end

#dataObject

Returns the value of attribute data.



12
13
14
# File 'lib/tabled.rb', line 12

def data
  @data
end

#data_without_optionsObject

Returns the value of attribute data_without_options.



12
13
14
# File 'lib/tabled.rb', line 12

def data_without_options
  @data_without_options
end

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/tabled.rb', line 12

def options
  @options
end

Instance Method Details



21
22
23
# File 'lib/tabled.rb', line 21

def print_to_console
  print content.join("\n")
end