google-qr 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/google-qr.rb +27 -0
  2. metadata +68 -0
data/lib/google-qr.rb ADDED
@@ -0,0 +1,27 @@
1
+ class GoogleQR
2
+ BASE_URL = "https://chart.googleapis.com/chart?cht=qr&"
3
+ attr_accessor :data, :size
4
+ def initialize(opts={:data => "http://google.com"})
5
+ opts.each {|key,value| self.send("#{key}=", value) }
6
+ end
7
+
8
+ def to_s
9
+ if self.data
10
+ params = ["chl=#{self.data}"]
11
+ params << "chs=#{self.size}" if self.size
12
+ BASE_URL + params.join("&")
13
+ else
14
+ raise "Attribute @data is required for GoogleQR code"
15
+ end
16
+ end
17
+
18
+ def render
19
+ if self.size
20
+ height, width = self.size.split('x')
21
+ dimensions = " height='#{height}' width='#{width}' "
22
+ else
23
+ dimensions = nil
24
+ end
25
+ "<img src='#{self.to_s}'#{dimensions}/>"
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-qr
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Joseph Hsu
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2011-01-20 00:00:00 +00:00
17
+ default_executable:
18
+ dependencies: []
19
+
20
+ description: Generate URL string for Google QR code and render HTML img string
21
+ email:
22
+ - jhsu@josephhsu.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/google-qr.rb
31
+ has_rdoc: true
32
+ homepage: http://github.com/jhsu/google-qr
33
+ licenses: []
34
+
35
+ post_install_message:
36
+ rdoc_options: []
37
+
38
+ require_paths:
39
+ - lib
40
+ required_ruby_version: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ segments:
46
+ - 1
47
+ - 8
48
+ - 7
49
+ version: 1.8.7
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 1
57
+ - 3
58
+ - 6
59
+ version: 1.3.6
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: Wrapper for Google Chart QR code
67
+ test_files: []
68
+