class Nineteen::Eighty::Two::Formats::SVG
Public Class Methods
body(text)
click to toggle source
# File lib/nineteen/eighty/two/formatters/svg_formatter.rb, line 20 def self.body text rows = [] text.each_with_index do |line, count| Spectrum[line].each_with_index do |line, index| rows.push row(line, index + (count * 8)) end end rows.flatten end
format(text, options = {})
click to toggle source
# File lib/nineteen/eighty/two/formatters/svg_formatter.rb, line 6 def self.format text, options = {} text = [text] unless text.is_a? Array t = File.read File.open File.join Nineteen::Eighty::Two.templates_dir, 'svg', 'document.eruby' context = { width: text.longest * 8, height: text.count * 8, fill_colour: options.fetch(:colour, nil), class: options.fetch(:class, nil), body: body(text) } Erubis::Eruby.new(t).evaluate(context) end
longest(list)
click to toggle source
# File lib/nineteen/eighty/two/formatters/svg_formatter.rb, line 51 def self.longest list list.map { |i| i.length }.max end
row(list, index = 0)
click to toggle source
# File lib/nineteen/eighty/two/formatters/svg_formatter.rb, line 30 def self.row list, index = 0 x = 0 cells = [] Decorators::RunLengthEncoder.encode(list).each do |item| if item.type == 1 t = File.read File.open File.join Nineteen::Eighty::Two.templates_dir, 'svg', 'cell.eruby' context = { x: x, y: index, width: item.width, height: 1, style: 'on' } cells.push Erubis::Eruby.new(t).evaluate(context).strip end x += item.width end cells end