Class: Nineteen::Eighty::Two::Formats::SVG
- Inherits:
-
Object
- Object
- Nineteen::Eighty::Two::Formats::SVG
- Defined in:
- lib/nineteen/eighty/two/formatters/svg_formatter.rb
Class Method Summary collapse
- .body(text) ⇒ Object
- .format(text, options = {}) ⇒ Object
- .longest(list) ⇒ Object
- .row(list, index = 0) ⇒ Object
Class Method Details
.body(text) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/nineteen/eighty/two/formatters/svg_formatter.rb', line 19 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 = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/nineteen/eighty/two/formatters/svg_formatter.rb', line 6 def self.format text, = {} 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: .fetch(:colour, '#000000'), body: body(text) } Erubis::Eruby.new(t).evaluate(context) end |
.longest(list) ⇒ Object
50 51 52 |
# File 'lib/nineteen/eighty/two/formatters/svg_formatter.rb', line 50 def self.longest list list.map { |i| i.length }.max end |
.row(list, index = 0) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/nineteen/eighty/two/formatters/svg_formatter.rb', line 29 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 |