class Qrio::Matrix
Attributes
height[R]
width[R]
Public Class Methods
new(bits, width, height)
click to toggle source
# File lib/qrio/matrix.rb, line 5 def initialize(bits, width, height) @bits = bits @width = width @height = height end
Public Instance Methods
[](x, y)
click to toggle source
# File lib/qrio/matrix.rb, line 15 def [](x, y) rows[y][x] rescue nil end
[]=(x, y, value)
click to toggle source
# File lib/qrio/matrix.rb, line 19 def []=(x, y, value) raise "Matrix index out of bounds" if x >= width || y >= height @bits[(width * y) + x] = value @rows = @columns = nil end
columns()
click to toggle source
# File lib/qrio/matrix.rb, line 39 def columns @columns ||= begin columns = [] width.times do |index| column = [] rows.each do |row| column << row[index] end columns << column end columns end end
extract(x, y, width, height)
click to toggle source
# File lib/qrio/matrix.rb, line 64 def extract(x, y, width, height) new_bits = [] height.times do |offset| new_bits += rows[y + offset].slice(x, width) end self.class.new(new_bits, width, height) end
rotate()
click to toggle source
# File lib/qrio/matrix.rb, line 56 def rotate new_bits = [] columns.each do |column| new_bits += column.reverse end self.class.new(new_bits, @height, @width) end
rows()
click to toggle source
# File lib/qrio/matrix.rb, line 25 def rows @rows ||= begin rows = [] bits = @bits.dup while row = bits.slice!(0, @width) break if row.nil? || row.empty? rows << row end rows end end
to_s()
click to toggle source
# File lib/qrio/matrix.rb, line 11 def to_s "<Matrix width:#{ width }, height: #{ height }>" end