Sha256: fd65d1b22654f8e8ffb23b15c9d75780680f318f86ee0c474f6f9cf36a97b32f
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
module Nineteen module Eighty module Two module Formatters class HTMLTableFormatter def self.format text s = '<!-- %s -->' % text s << '<table class="sinclair">' lines = Spectrum[text] s << self.build_row(self.make_blanks(lines.first)) lines.each { |line| s << self.build_row(Nineteen::Eighty::Two::Decorators::RunLengthEncoder.encode line) } s << '</table>' s end def self.make_blanks text a = [] (text.length * 8).times do |bit| a << { 0 => 1 } end a end def self.convert_line line line.map! { |i| { :class => i.keys[0] == 1 ? "on" : "off", :colspan => i.values[0] } } end def self.build_row line s = '<tr class="sinclair">' convert_line line line.each do |bit| s << '<td class="%s"' % bit[:class] if bit[:colspan] > 1 s << ' colspan="%d"' % bit[:colspan] end s << '> </td>' end s << '</tr>' s end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
nineteen-eighty-two-0.1.0 | lib/nineteen/eighty/two/formatters/html_table_formatter.rb |