Class: RqrcodePngBin::App
- Inherits:
-
Object
- Object
- RqrcodePngBin::App
- Defined in:
- lib/rqrcode_png_bin/app.rb
Instance Attribute Summary collapse
-
#canvas ⇒ Object
readonly
Returns the value of attribute canvas.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#initialize(argv = []) ⇒ App
constructor
A new instance of App.
-
#opts ⇒ Object
- return
-
Hash.
-
#parser ⇒ Object
- return
-
OptionParser.
- #run ⇒ Object
-
#str ⇒ Object
- return
-
String.
Constructor Details
#initialize(argv = []) ⇒ App
Returns a new instance of App.
6 7 8 9 10 11 12 13 |
# File 'lib/rqrcode_png_bin/app.rb', line 6 def initialize(argv = []) @argv = argv @size = 4 @level = :m @canvas = nil parser.parse!(@argv) end |
Instance Attribute Details
#canvas ⇒ Object (readonly)
Returns the value of attribute canvas.
14 15 16 |
# File 'lib/rqrcode_png_bin/app.rb', line 14 def canvas @canvas end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
14 15 16 |
# File 'lib/rqrcode_png_bin/app.rb', line 14 def level @level end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
14 15 16 |
# File 'lib/rqrcode_png_bin/app.rb', line 14 def size @size end |
Instance Method Details
#opts ⇒ Object
- return
-
Hash
37 38 39 40 41 42 |
# File 'lib/rqrcode_png_bin/app.rb', line 37 def opts h = { :size => @size, :level => @level } end |
#parser ⇒ Object
- return
-
OptionParser
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rqrcode_png_bin/app.rb', line 47 def parser OptionParser.new do |opt| opt.version = VERSION opt. = "Usage: rqrcode_png [option] string" opt.on('-s', '--size SIZE (default 4)') {|v| re = %r{\A[0-9]+\z} if v =~ re @size = v.to_i else raise ArgumentError, "option size should match #{re}" end } opt.on('-l', '--level LEVEL (default m)') {|v| = %w(l m q h) if .include?(v) @level = v.to_sym else raise ArgumentError, "option level should be included #{options}" end } opt.on('-c', '--canvas CANVAS (ex 200x200)') {|v| re = %r{\A([0-9]+)x([0-9]+)\z} if v =~ re @canvas = [$1.to_i, $2.to_i] else raise ArgumentError, "option canvas should match #{re}" end } end end |
#run ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rqrcode_png_bin/app.rb', line 16 def run if str png = RQRCode::QRCode.new(str, opts).to_img png = png.resize(*canvas) if canvas STDOUT.puts png else STDERR.puts "rqrcode_png #{VERSION}", nil, parser.help end end |
#str ⇒ Object
- return
-
String
30 31 32 |
# File 'lib/rqrcode_png_bin/app.rb', line 30 def str str = @argv.first end |