Module: Drawille::Frameable
Constant Summary collapse
- PIXEL_MAP =
[[0x01, 0x08], [0x02, 0x10], [0x04, 0x20], [0x40, 0x80]]
- BRAILLE_CHAR_OFFSET =
0x2800
Instance Method Summary collapse
- #char(x, y) ⇒ Object
- #frame(options = {}) ⇒ Object
- #row(y, options = {}) ⇒ Object
- #rows(options = {}) ⇒ Object
- #to_braille(x) ⇒ Object
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 ={} rows().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, ={} chars = [:chars] || @chars row = chars[y] min = [:min_x] max = [: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 ={} chars = [:chars] || @chars min = [:min_y] || [(chars.keys.min || 0), 0].min max = [:max_y] || chars.keys.max return [] if min.nil? || max.nil? [:min_x] ||= [chars.reduce([]) { |m,x| m << x.last.keys }.flatten.min, 0].min [:max_x] ||= chars.reduce([]) { |m,x| m << x.last.keys }.flatten.max (min..max).map { |i| row i, } 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 |