grcode 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/Manifest +4 -0
  2. data/README.rdoc +36 -0
  3. data/Rakefile +14 -0
  4. data/grcode.gemspec +29 -0
  5. data/lib/grcode.rb +34 -0
  6. metadata +76 -0
@@ -0,0 +1,4 @@
1
+ Manifest
2
+ README.rdoc
3
+ Rakefile
4
+ lib/grcode.rb
@@ -0,0 +1,36 @@
1
+ = Grcode
2
+
3
+ Grcode is a plain simple wrapper for generating Qrcode images using Google API ( http://code.google.com/intl/es-ES/apis/chart/infographics/docs/qr_codes.html )
4
+
5
+ == How to use it
6
+
7
+ A piece of code worth 1000 words :)
8
+
9
+ >> require 'grcode'
10
+ => true
11
+ >> qr = Grcode::QRCode.new('Hello world of ruby lovers!')
12
+ => #<Grcode::QRCode:0x100522af0 @url="https://chart.googleapis.com/chart?cht=qr&chl=Hello world of ruby lovers!&chs=150x150">
13
+ >> qr.url
14
+ => "https://chart.googleapis.com/chart?cht=qr&chl=Hello world of ruby lovers!&chs=150x150"
15
+
16
+ == Options
17
+
18
+ Along with the string to encode, you can pass some other options that Google API supports:
19
+
20
+ * Size
21
+ * Encoding
22
+ * Correction
23
+ * Margin
24
+
25
+ Some more examples:
26
+
27
+ >> qr = Grcode::QRCode.new('Hello world of ruby lovers!', {:size => 300})
28
+ => #<Grcode::QRCode:0x100520138 @url="https://chart.googleapis.com/chart?cht=qr&chl=Hello world of ruby lovers!&chs=300x300">
29
+ >> qr.url
30
+ => "https://chart.googleapis.com/chart?cht=qr&chl=Hello world of ruby lovers!&chs=300x300"
31
+
32
+ >> qr = Grcode::QRCode.new('Hello world of ruby lovers!', {:size => 300, :margin => 5})
33
+ => #<Grcode::QRCode:0x100513bb8 @url="https://chart.googleapis.com/chart?cht=qr&chld=L|5&chl=Hello world of ruby lovers!&chs=300x300">
34
+ >> qr.url
35
+ => "https://chart.googleapis.com/chart?cht=qr&chld=L|5&chl=Hello world of ruby lovers!&chs=300x300"
36
+
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('grcode', '0.1.0') do |p|
6
+ p.description = "Simple wrapper for Google's QRCode generator"
7
+ p.url = "http://github.com/eltercero/grcode"
8
+ p.author = "Victor Martin"
9
+ p.email = "victor.martin84@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{grcode}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = [%q{Victor Martin}]
9
+ s.date = %q{2011-09-07}
10
+ s.description = %q{Simple wrapper for Google's QRCode generator}
11
+ s.email = %q{victor.martin84@gmail.com}
12
+ s.extra_rdoc_files = [%q{README.rdoc}, %q{lib/grcode.rb}]
13
+ s.files = [%q{Manifest}, %q{README.rdoc}, %q{Rakefile}, %q{lib/grcode.rb}, %q{grcode.gemspec}]
14
+ s.homepage = %q{http://github.com/eltercero/grcode}
15
+ s.rdoc_options = [%q{--line-numbers}, %q{--inline-source}, %q{--title}, %q{Grcode}, %q{--main}, %q{README.rdoc}]
16
+ s.require_paths = [%q{lib}]
17
+ s.rubyforge_project = %q{grcode}
18
+ s.rubygems_version = %q{1.8.6}
19
+ s.summary = %q{Simple wrapper for Google's QRCode generator}
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ else
26
+ end
27
+ else
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ module Grcode
2
+ class QRCode
3
+ attr_reader :url
4
+
5
+ def initialize(string, options={})
6
+ unless string.is_a? String
7
+ raise "GRCode expected an String, but it found a #{string.class}"
8
+ end
9
+
10
+ url_options = {}
11
+ url_options[:cht] = 'qr' # Tell google we want a QRCode
12
+ url_options[:chl] = string
13
+ url_options[:chs] = options[:size] ? "#{options[:size]}x#{options[:size]}" : '150x150'
14
+ if options[:encoding]
15
+ url_options[:choe] = options[:encoding]
16
+ end
17
+
18
+ if options[:correction] || options[:margin]
19
+ correction = options[:correction] || 'L'
20
+ margin = options[:margin] || '4'
21
+ url_options[:chld] = "#{correction}|#{margin}"
22
+ end
23
+
24
+ @url = make_url(url_options)
25
+ end
26
+
27
+ protected
28
+ def make_url(options)
29
+ params = options.collect{|k,v| "#{k}=#{v}"}.join('&')
30
+
31
+ "https://chart.googleapis.com/chart?#{params}"
32
+ end
33
+ end
34
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grcode
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Victor Martin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-07 00:00:00 Z
19
+ dependencies: []
20
+
21
+ description: Simple wrapper for Google's QRCode generator
22
+ email: victor.martin84@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ - lib/grcode.rb
30
+ files:
31
+ - Manifest
32
+ - README.rdoc
33
+ - Rakefile
34
+ - lib/grcode.rb
35
+ - grcode.gemspec
36
+ homepage: http://github.com/eltercero/grcode
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --line-numbers
42
+ - --inline-source
43
+ - --title
44
+ - Grcode
45
+ - --main
46
+ - README.rdoc
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ hash: 3
55
+ segments:
56
+ - 0
57
+ version: "0"
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ hash: 11
64
+ segments:
65
+ - 1
66
+ - 2
67
+ version: "1.2"
68
+ requirements: []
69
+
70
+ rubyforge_project: grcode
71
+ rubygems_version: 1.8.6
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: Simple wrapper for Google's QRCode generator
75
+ test_files: []
76
+