Class: Rerout::QrOptions
- Inherits:
-
Object
- Object
- Rerout::QrOptions
- Defined in:
- lib/rerout/qr_options.rb
Overview
Options for the QR endpoint. All fields are optional.
-
‘size` (Integer): module size in px (1..32). Server default 8.
-
‘margin` (Integer): quiet zone in modules (0..16). Server default 4.
-
‘ecc` (String): error correction level. One of `L`, `M`, `Q`, `H`.
-
‘domain` (String): force the QR to encode a specific verified custom domain.
-
‘refresh` (String, true): cache-bust on regenerate. `true` is serialized as `“1”`.
Constant Summary collapse
- ALLOWED_ECC =
%w[L M Q H].freeze
Instance Attribute Summary collapse
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
-
#ecc ⇒ Object
readonly
Returns the value of attribute ecc.
-
#margin ⇒ Object
readonly
Returns the value of attribute margin.
-
#refresh ⇒ Object
readonly
Returns the value of attribute refresh.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
True when no field is set.
-
#initialize(size: nil, margin: nil, ecc: nil, domain: nil, refresh: nil) ⇒ QrOptions
constructor
A new instance of QrOptions.
-
#to_query_hash ⇒ Object
Serialize options as a ‘{ key => string }` hash ready to be turned into a query string.
Constructor Details
#initialize(size: nil, margin: nil, ecc: nil, domain: nil, refresh: nil) ⇒ QrOptions
Returns a new instance of QrOptions.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rerout/qr_options.rb', line 16 def initialize(size: nil, margin: nil, ecc: nil, domain: nil, refresh: nil) if ecc && !ALLOWED_ECC.include?(ecc.to_s) raise ArgumentError, "ecc must be one of #{ALLOWED_ECC.inspect}, got #{ecc.inspect}" end @size = size @margin = margin @ecc = ecc @domain = domain @refresh = refresh freeze end |
Instance Attribute Details
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
12 13 14 |
# File 'lib/rerout/qr_options.rb', line 12 def domain @domain end |
#ecc ⇒ Object (readonly)
Returns the value of attribute ecc.
12 13 14 |
# File 'lib/rerout/qr_options.rb', line 12 def ecc @ecc end |
#margin ⇒ Object (readonly)
Returns the value of attribute margin.
12 13 14 |
# File 'lib/rerout/qr_options.rb', line 12 def margin @margin end |
#refresh ⇒ Object (readonly)
Returns the value of attribute refresh.
12 13 14 |
# File 'lib/rerout/qr_options.rb', line 12 def refresh @refresh end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
12 13 14 |
# File 'lib/rerout/qr_options.rb', line 12 def size @size end |
Instance Method Details
#empty? ⇒ Boolean
Returns true when no field is set.
30 31 32 |
# File 'lib/rerout/qr_options.rb', line 30 def empty? size.nil? && margin.nil? && ecc.nil? && domain.nil? && refresh.nil? end |
#to_query_hash ⇒ Object
Serialize options as a ‘{ key => string }` hash ready to be turned into a query string. `refresh: true` becomes `“1”`.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rerout/qr_options.rb', line 36 def to_query_hash out = {} out['size'] = size.to_s unless size.nil? out['margin'] = margin.to_s unless margin.nil? out['ecc'] = ecc.to_s unless ecc.nil? out['domain'] = domain.to_s unless domain.nil? unless refresh.nil? out['refresh'] = refresh == true ? '1' : refresh.to_s end out end |