Class: Tabled::ContentShaper

Inherits:
Object
  • Object
show all
Defined in:
lib/content_shaper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, columns_width, options) ⇒ ContentShaper

Returns a new instance of ContentShaper.



7
8
9
10
11
# File 'lib/content_shaper.rb', line 7

def initialize(data, columns_width, options)
  @data = data
  @columns_width = columns_width
  @options = options
end

Instance Attribute Details

#columns_widthObject

Returns the value of attribute columns_width.



5
6
7
# File 'lib/content_shaper.rb', line 5

def columns_width
  @columns_width
end

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/content_shaper.rb', line 5

def data
  @data
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/content_shaper.rb', line 5

def options
  @options
end

Instance Method Details

#shapeObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/content_shaper.rb', line 13

def shape
  content = []

  unless options[:titles].empty?
    content << Tabled::Template::Titles.render(options[:titles], columns_width, options[:framed])
    content << (options[:row_separator].to_s * row_length) unless options[:row_separator].nil?
  end

  content.concat(
    data
    .each_with_object([]) do |row, enumerator|
      enumerator << Tabled::Template::Row.render(row, columns_width, options[:framed])
      enumerator << Tabled::Template::RowFooter.render(row, columns_width, options[:framed])

      #  Row separator
      enumerator << (options[:row_separator].to_s * row_length) unless options[:row_separator].nil?
    end
    .compact
  )

  content = add_left_and_right_borders(content)
  add_top_bottom_borders(content)
end