Skip to content

Commit

Permalink
Merge pull request #36 from pikesley/reduce-complexity
Browse files Browse the repository at this point in the history
Readability improvements
  • Loading branch information
Sam Pikesley committed Nov 16, 2013
2 parents 23b2f21 + 4f10658 commit 07716e1
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions lib/uncle_clive/formatters/html_table_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,62 +11,51 @@ def render font_generator, key
if @rle
font_generator = UncleClive::Decorators::RunLengthEncoder.new font_generator
end
s = '<!-- %s -->' % [
key
]
s = '<!-- %s -->' % key
s << '<table class="sinclair">'

lines = font_generator.get(key)
if @rle
lines << make_blanks(key)
end

lines.each do |line|
s << build_row(line)
end
lines.each { |line| s << build_row(line) }

s << '</table>'

s
end

def make_blanks key
a = []
(key.length * 8).times do |bit|
a << {
0 => 1
}
a << { 0 => 1 }
end

a
end

def convert_line line
line.map! { |i|
{
:class => i.keys[0] == 1 ? "on" : "off",
:colspan => i.values[0]
}
}
end

def build_row line
s = '<tr class="sinclair">'

if not @rle
line.map! do |i|
{
i => 1
}
end
line.map! { |i| { i => 1 } }
end

line.map! do |i|
{
:class => i.keys[0] == 1 ? "on" : "off",
:colspan => i.values[0]
}
end
convert_line line

line.each do |bit|
s << '<td class="%s"' % [
bit[:class]
]
s << '<td class="%s"' % bit[:class]
if bit[:colspan] > 1
s << ' colspan="%d"' % [
bit[:colspan]
]
s << ' colspan="%d"' % bit[:colspan]
end
s << '> </td>'
end
Expand Down

0 comments on commit 07716e1

Please sign in to comment.