module Drawille::Frameable

Constants

BRAILLE_CHAR_OFFSET
PIXEL_MAP

Public Instance Methods

char(x, y) click to toggle source
# File lib/drawille/frameable.rb, line 36
def char x, y
  to_braille @chars[y][x]
end
frame(options={}) click to toggle source
# File lib/drawille/frameable.rb, line 32
def frame options={}
  rows(options).join("\n")
end
row(y, options={}) click to toggle source
# File lib/drawille/frameable.rb, line 13
def row y, options={}
  chars = options[:chars] || @chars
  row   = chars[y]
  min   = options[:min_x]
  max   = options[:max_x]
  return "" if min.nil? || max.nil?
  (min..max).reduce("") { |memo, i| memo << to_braille(row.nil? ? 0 : row[i] || 0) }
end
rows(options={}) click to toggle source
# File lib/drawille/frameable.rb, line 22
def rows options={}
  chars = options[:chars] || @chars
  min   = options[:min_y] || [(chars.keys.min || 0), 0].min
  max   = options[:max_y] ||  chars.keys.max
  return [] if min.nil? || max.nil?
  options[:min_x] ||= [chars.reduce([]) { |m,x| m << x.last.keys }.flatten.min, 0].min
  options[:max_x] ||=  chars.reduce([]) { |m,x| m << x.last.keys }.flatten.max
  (min..max).map { |i| row i, options }
end
to_braille(x) click to toggle source
# File lib/drawille/frameable.rb, line 40
def to_braille x
  [BRAILLE_CHAR_OFFSET + x].pack("U*")
end