jabbrwcky/prawn-qrcode

#render_qr_code :stroke option defaults to false erroneously

MarkDBlackwell opened this issue · 2 comments

Method #render_qr_code's documentation says its :stroke option defaults to true (nicely).

However, a run of the repository's prepared_qrcode example shows this default isn't working right.

When the :stroke option isn't given, the expression in line 84 evaluates to nil: stroke = (opt.has_key?(:stroke) && opt[:stroke].nil?) || opt[:stroke].

Perhaps this line of code should be:
stroke = !opt.has_key?(:stroke) || opt[:stroke].nil? || opt[:stroke].

Or (instead), perhaps this functionality would be more clear, if written as:

stroke = true # default.
stroke = opt[:stroke].nil? || opt[:stroke] if opt.has_key? :stroke

A ! fixed it.
stroke = !(opt.has_key?(:stroke) && opt[:stroke].nil?) || opt[:stroke]

Hm...the docs seem to say invokers can pass any Boolean value (including false):

+:stroke+:: boolean value whether to draw bounds around the QR Code.

Unfortunately, if the invoker passes {stroke: false} as the options argument, your new code (above) changes false to true. :(

d379cb7 resolves this—I'm happy I was able to help! :)