Permalink
Browse files

refactored #dark_squares_only to QRQCodePNG::Sequence

  • Loading branch information...
1 parent 0e1e763 commit ee27a85142220e608fa4e355cfa0aef98c211583 @DCarper committed Oct 14, 2011
View
@@ -1,8 +1,9 @@
-require "chunky_png"
+require 'chunky_png'
require 'rqrcode'
-require "rqrcode_png/version"
-require "rqrcode_png/image"
-require "rqrcode_png/qrcode_extensions"
+require 'rqrcode_png/version'
+require 'rqrcode_png/sequence'
+require 'rqrcode_png/image'
+require 'rqrcode_png/qrcode_extensions'
RQRCode::QRCode.send :include, RQRCodePNG::QRCodeExtensions
View
@@ -6,10 +6,8 @@ class Image
BLACK = ::ChunkyPNG::Color::BLACK
WHITE = ::ChunkyPNG::Color::WHITE
- attr_accessor :qr_code
-
def initialize(qr_code)
- self.qr_code = qr_code
+ @sequence = Sequence.new(qr_code)
end
#
@@ -18,7 +16,7 @@ def initialize(qr_code)
def render
png = blank_img()
- qr_code().dark_squares_only do |x, y|
+ @sequence.dark_squares_only do |x, y|
png[y + BORDER, x + BORDER] = BLACK
end
@@ -1,25 +1,13 @@
module RQRCodePNG
module QRCodeExtensions
+
+ #
# This method returns a 33x33 .png of the code
#
def to_img
return Image.new(self).render()
end
-
- #
- # This method yields the vertices of the dark squares
- #
- def dark_squares_only(&block)
- self.modules.each_index do |row|
- self.modules.each_index do |column|
- if self.dark?(row, column)
- yield row, column
- end
- end
- end
-
- end
end
end
@@ -0,0 +1,24 @@
+module RQRCodePNG
+
+ class Sequence
+
+ def initialize(qr_code)
+ @qr_code = qr_code
+ end
+
+ #
+ # This method yields the vertices of the dark squares
+ #
+ def dark_squares_only(&block)
+ @qr_code.modules.each_index do |row|
+ @qr_code.modules.each_index do |column|
+ if @qr_code.dark?(row, column)
+ yield row, column
+ end
+ end
+ end
+
+ end
+
+ end
+end
@@ -1,3 +1,3 @@
module RqrcodePng
- VERSION = "0.0.1"
+ VERSION = "0.1.0"
end

0 comments on commit ee27a85

Please sign in to comment.