module Lays
Constants
- Layer
- VERSION
Public Instance Methods
[](layer)
click to toggle source
# File lib/lays.rb, line 21 def [](layer) set_layer(layer) layers[layer] end
[]=(layer, content)
click to toggle source
# File lib/lays.rb, line 15 def []=(layer, content) set_layer(layer) layers[layer].content = content @result = nil end
height()
click to toggle source
# File lib/lays.rb, line 59 def height layers.count end
layers()
click to toggle source
# File lib/lays.rb, line 30 def layers @layers ||= {} end
render()
click to toggle source
# File lib/lays.rb, line 38 def render result = [] lays = layers.sort {|a, b| a[0] <=> b[0] } lays.each do |key, layer| content = layer.content content.split("\n").each_with_index.map do |line, i| line.each_char.each_with_index do |c, j| result[i] ||= [] if space_char_for(layer, c) result[i][j] = " " elsif !transparent_char_for(layer, c) result[i][j] = c elsif key == lays.first.first result[i][j] = " " end end end end result.map {|a|a.join}.join("\n") end
set_layer(id)
click to toggle source
# File lib/lays.rb, line 26 def set_layer(id) layers[id] ||= Layer.new end
space_char()
click to toggle source
# File lib/lays.rb, line 88 def space_char @space_char end
space_char=(char)
click to toggle source
# File lib/lays.rb, line 83 def space_char=(char) @space_char = char @transparent_char = nil end
space_char_for(layer, char)
click to toggle source
# File lib/lays.rb, line 92 def space_char_for(layer, char) char == layer.space_char || char == space_char end
to_s()
click to toggle source
# File lib/lays.rb, line 34 def to_s @result ||= render end
transparent_char()
click to toggle source
# File lib/lays.rb, line 74 def transparent_char @transparent_char ||= " " end
transparent_char=(char)
click to toggle source
# File lib/lays.rb, line 69 def transparent_char=(char) @transparent_char = char @space_char = nil end
transparent_char_for(layer, char)
click to toggle source
# File lib/lays.rb, line 78 def transparent_char_for(layer, char) transparent = layer.transparent_char || transparent_char char == transparent end
width()
click to toggle source
# File lib/lays.rb, line 63 def width layers.max { |a, b| a.last.content.size <=> b.last.content.size }.last.content.size end