Module: Drawille::Frameable

Included in:
Canvas, FlipBook
Defined in:
lib/drawille/frameable.rb

Constant Summary collapse

PIXEL_MAP =
[[0x01, 0x08], 
[0x02, 0x10], 
[0x04, 0x20], 
[0x40, 0x80]]
BRAILLE_CHAR_OFFSET =
0x2800

Instance Method Summary collapse

Instance Method Details

#char(x, y) ⇒ Object



37
38
39
# File 'lib/drawille/frameable.rb', line 37

def char x, y
  to_braille @chars[y][x]
end

#frame(options = {}) ⇒ Object



33
34
35
# File 'lib/drawille/frameable.rb', line 33

def frame options={}
  rows(options).join("\n")
end

#row(y, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/drawille/frameable.rb', line 14

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 = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/drawille/frameable.rb', line 23

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) ⇒ Object



41
42
43
# File 'lib/drawille/frameable.rb', line 41

def to_braille x
  [BRAILLE_CHAR_OFFSET + x].pack("U*")
end