Class: Nineteen::Eighty::Two::Formats::HTMLTable

Inherits:
Object
  • Object
show all
Defined in:
lib/nineteen/eighty/two/formatters/html_table_formatter.rb

Class Method Summary collapse

Class Method Details

.blanks(lines) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/nineteen/eighty/two/formatters/html_table_formatter.rb', line 18

def self.blanks lines
  t = File.read File.open File.join Nineteen::Eighty::Two.templates_dir, 'html', 'table', 'row.eruby'
  context = {
    cells: lines.map { |b| cell Span.new(0, 1) }.join
  }
  Erubis::Eruby.new(t).evaluate(context).strip
end

.cell(span) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/nineteen/eighty/two/formatters/html_table_formatter.rb', line 26

def self.cell span
  t = File.read File.open File.join Nineteen::Eighty::Two.templates_dir, 'html', 'table', 'cell.eruby'
  context = {
    style: span.type == 1 ? 'on' : 'off',
  }
  context[:colspan] = span.width if span.width > 1
  Erubis::Eruby.new(t).evaluate(context).strip
end

.format(text) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/nineteen/eighty/two/formatters/html_table_formatter.rb', line 6

def self.format text
  lines = Spectrum[*text]

  t = File.read File.open File.join Nineteen::Eighty::Two.templates_dir, 'html', 'table', 'table.eruby'
  context = {
    title: text.to_s.gsub('"', ''),
    blanks: blanks(lines.first),
    rows: lines.map { |l| row(l) }.join("\n")
  }
  Erubis::Eruby.new(t).evaluate(context).strip
end

.row(list) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/nineteen/eighty/two/formatters/html_table_formatter.rb', line 35

def self.row list
  t = File.read File.open File.join Nineteen::Eighty::Two.templates_dir, 'html', 'table', 'row.eruby'
  context = {
    cells: Decorators::RunLengthEncoder.encode(list).map { |i| cell i }.join
  }
  Erubis::Eruby.new(t).evaluate(context).strip
end