google-qr 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/google-qr.rb +40 -11
- metadata +4 -4
data/lib/google-qr.rb
CHANGED
@@ -2,15 +2,10 @@ require 'string'
|
|
2
2
|
require 'uri'
|
3
3
|
|
4
4
|
class GoogleQR
|
5
|
-
attr_accessor :data,
|
6
|
-
:size,
|
7
|
-
:use_https,
|
8
|
-
:encoding,
|
9
|
-
:error_correction
|
5
|
+
attr_accessor :data, :size, :use_https, :encoding, :error_correction, :margin, :html_options
|
10
6
|
|
11
7
|
def initialize(opts={})
|
12
8
|
options = {
|
13
|
-
:data => "GoogleQR",
|
14
9
|
:size => "100x100",
|
15
10
|
:use_https => true
|
16
11
|
}.merge!(opts)
|
@@ -20,10 +15,10 @@ class GoogleQR
|
|
20
15
|
|
21
16
|
def to_s
|
22
17
|
if self.data
|
23
|
-
params = ["chl=#{
|
24
|
-
params << "chs=#{self.size}"
|
18
|
+
params = ["chl=#{escape_string(self.data)}"]
|
19
|
+
params << "chs=#{self.size}"
|
25
20
|
params << "choe=#{self.encoding}" if self.encoding
|
26
|
-
params <<
|
21
|
+
params << error_correction_params if error_correction_param?
|
27
22
|
base_url + params.join("&")
|
28
23
|
else
|
29
24
|
raise "Attribute @data is required for GoogleQR code"
|
@@ -37,11 +32,45 @@ class GoogleQR
|
|
37
32
|
else
|
38
33
|
dimensions = nil
|
39
34
|
end
|
40
|
-
|
35
|
+
|
36
|
+
if self.html_options
|
37
|
+
html_options = ""
|
38
|
+
|
39
|
+
self.html_options.each do |k, v|
|
40
|
+
if k.to_s.length > 0 && v.to_s.length > 0
|
41
|
+
html_options += k.to_s + "='" + v.to_s + "' "
|
42
|
+
end
|
43
|
+
end
|
44
|
+
else
|
45
|
+
html_options = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
"<img src='#{self.to_s}'#{dimensions}#{html_options}/>"
|
41
49
|
end
|
42
50
|
|
43
51
|
private
|
44
52
|
def base_url
|
45
53
|
"http#{self.use_https ? 's' : ''}://chart.googleapis.com/chart?cht=qr&"
|
46
54
|
end
|
47
|
-
|
55
|
+
|
56
|
+
def error_correction_param?
|
57
|
+
self.error_correction || self.margin
|
58
|
+
end
|
59
|
+
|
60
|
+
def error_correction_params
|
61
|
+
if !self.error_correction && self.margin
|
62
|
+
param = "L|#{self.margin}"
|
63
|
+
elsif self.error_correction && !self.margin
|
64
|
+
param = self.error_correction
|
65
|
+
else
|
66
|
+
param = "#{self.error_correction}|#{self.margin}"
|
67
|
+
end
|
68
|
+
|
69
|
+
"chld=#{escape_string(param)}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def escape_string(string)
|
73
|
+
URI.encode(string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google-qr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,12 +10,12 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2012-05-11 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
15
|
description: Generate URL string for Google QR code and render HTML img string
|
16
16
|
email:
|
17
17
|
- jhsu@josephhsu.com
|
18
|
-
-
|
18
|
+
- nick@nickhammond.com
|
19
19
|
executables: []
|
20
20
|
extensions: []
|
21
21
|
extra_rdoc_files: []
|
@@ -42,7 +42,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
42
|
version: 1.3.6
|
43
43
|
requirements: []
|
44
44
|
rubyforge_project:
|
45
|
-
rubygems_version: 1.8.
|
45
|
+
rubygems_version: 1.8.21
|
46
46
|
signing_key:
|
47
47
|
specification_version: 3
|
48
48
|
summary: Wrapper for Google Chart QR code
|