rqrcode_png 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -16,7 +16,7 @@ png = qr.to_img # returns an instance of ChunkyPNG
16
16
  png.resize(90, 90).save("really_cool_qr_image.png")
17
17
  ```
18
18
 
19
- *NOTE:* For now, the :size of the QR code has to be 5 or less. Working on this.
19
+ *NOTE:* For now, the :size of the QR code has to be 14 or less. Working on this.
20
20
 
21
21
  ### Bundler
22
22
  ```ruby
@@ -1,43 +1,33 @@
1
1
  module RQRCodePNG
2
- class Image
3
- BLACK = ::ChunkyPNG::Color::BLACK
4
- WHITE = ::ChunkyPNG::Color::WHITE
5
-
6
- def initialize(qr_code)
7
- @sequence = Sequence.new(qr_code)
8
- end
9
-
10
- #
11
- # Returns an image file of the QR Code
12
- #
13
- def render
14
- png = blank_img()
15
-
16
- @sequence.dark_squares_only do |x, y|
17
- png[y + @sequence.border_width(), x + @sequence.border_width()] = BLACK
18
- end
19
-
20
- return png
21
- end
22
-
23
- private
24
-
25
- #
26
- # Returns the size of the image
27
- #
28
- def img_size()
29
- @img_size ||= @sequence.img_size() +
30
- @sequence.border_width() * 2
31
- end
32
-
33
- #
34
- # Returns an appropriately sized, blank (white) image
35
- #
36
- def blank_img
37
- ::ChunkyPNG::Image.new( img_size(),
38
- img_size(),
39
- WHITE )
40
- end
41
-
42
- end
2
+ class Image
3
+ BLACK = ::ChunkyPNG::Color::BLACK
4
+ WHITE = ::ChunkyPNG::Color::WHITE
5
+ TRANSPARENT = ::ChunkyPNG::Color::TRANSPARENT
6
+
7
+ def initialize(qr_code)
8
+ @sequence = Sequence.new(qr_code)
9
+ end
10
+
11
+ # Returns an image file of the QR Code
12
+ def render bg_color = WHITE
13
+ png = blank_img(bg_color)
14
+ @sequence.dark_squares_only do |x, y|
15
+ png[y + @sequence.border_width(), x + @sequence.border_width()] = BLACK
16
+ end
17
+ return png
18
+ end
19
+
20
+ private
21
+
22
+ # Returns the size of the image
23
+ def img_size()
24
+ @img_size ||= @sequence.img_size() + @sequence.border_width() * 2
25
+ end
26
+
27
+ # Returns an appropriately sized, blank (white) image
28
+ def blank_img bg_color = WHITE
29
+ ::ChunkyPNG::Image.new(img_size(), img_size(), bg_color)
30
+ end
31
+ end
43
32
  end
33
+
@@ -1,13 +1,9 @@
1
1
  module RQRCodePNG
2
-
3
- module QRCodeExtensions
4
-
5
- #
6
- # This method returns a 33x33 .png of the code
7
- #
8
- def to_img
9
- return Image.new(self).render()
10
- end
11
-
12
- end
2
+ module QRCodeExtensions
3
+ # This method returns a 33x33 .png of the code
4
+ def to_img(bg_color = ChunkyPNG::Color::WHITE)
5
+ return Image.new(self).render(bg_color)
6
+ end
7
+ end
13
8
  end
9
+
@@ -1,37 +1,29 @@
1
1
  module RQRCodePNG
2
+ class Sequence
3
+ def initialize(qr_code)
4
+ @qr_code = qr_code
5
+ end
2
6
 
3
- class Sequence
4
-
5
- def initialize(qr_code)
6
- @qr_code = qr_code
7
- end
7
+ # This method yields the vertices of the dark squares
8
+ def dark_squares_only(&block)
9
+ @qr_code.modules.each_index do |row|
10
+ @qr_code.modules.each_index do |column|
11
+ if @qr_code.dark?(row, column)
12
+ yield row, column
13
+ end
14
+ end
15
+ end
16
+ end
8
17
 
9
- #
10
- # This method yields the vertices of the dark squares
11
- #
12
- def dark_squares_only(&block)
13
- @qr_code.modules.each_index do |row|
14
- @qr_code.modules.each_index do |column|
15
- if @qr_code.dark?(row, column)
16
- yield row, column
17
- end
18
- end
19
- end
18
+ # returns the image size by looking at how long the first line of the code is
19
+ def img_size
20
+ @img_size ||= @qr_code.to_s.split("\n").first.size()
21
+ end
20
22
 
21
- end
22
-
23
- #
24
- # returns the image size by looking at how long the first line of the code is
25
- #
26
- def img_size
27
- @img_size ||= @qr_code.to_s.split("\n").first.size()
28
- end
29
-
30
- #
31
- # Returns the border, 1/10 of the img size
32
- def border_width()
33
- @border ||= img_size() / 10
34
- end
35
-
36
- end
23
+ # Returns the border, 1/10 of the img size
24
+ def border_width()
25
+ @border ||= img_size() / 10
26
+ end
27
+ end
37
28
  end
29
+
@@ -1,3 +1,4 @@
1
1
  module RqrcodePng
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
4
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rqrcode_png
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-14 00:00:00.000000000Z
12
+ date: 2013-10-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chunky_png
16
- requirement: &2152638900 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152638900
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rqrcode
27
- requirement: &2152638480 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *2152638480
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  description: Glues rQRCode together with chunky_png
37
47
  email:
38
48
  - dcarper@dreamagile.com
@@ -71,8 +81,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
81
  version: '0'
72
82
  requirements: []
73
83
  rubyforge_project: rqrcode_png
74
- rubygems_version: 1.8.8
84
+ rubygems_version: 1.8.24
75
85
  signing_key:
76
86
  specification_version: 3
77
87
  summary: Produces a .png from a given QR Code
78
88
  test_files: []
89
+ has_rdoc: