Class: HealthCards::Chunk
- Inherits:
-
Object
- Object
- HealthCards::Chunk
- Defined in:
- lib/health_cards/chunk.rb
Overview
Represents a single QRCode in a sequence. This class is a shim to the RQRCode library to enable multimode encoding
Constant Summary collapse
- SINGLE_REGEX =
%r{shc:/}.freeze
- MULTI_REGEX =
%r{shc:/[0-9]*/[0-9]*/}.freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#ordinal ⇒ Object
readonly
Returns the value of attribute ordinal.
-
#qrcode ⇒ Object
readonly
Returns the value of attribute qrcode.
Instance Method Summary collapse
- #image ⇒ Object
-
#initialize(input:, ordinal: 1) ⇒ Chunk
constructor
A new instance of Chunk.
- #qr_code ⇒ Object
Constructor Details
#initialize(input:, ordinal: 1) ⇒ Chunk
Returns a new instance of Chunk.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/health_cards/chunk.rb', line 12 def initialize(input:, ordinal: 1) @ordinal = ordinal @data = input multi = MULTI_REGEX.match(input) prefix = multi ? multi.to_s : SINGLE_REGEX.match(input).to_s content = input.delete_prefix(prefix) @qrcode = RQRCode::QRCode.new([{ mode: :byte_8bit, data: prefix }, { mode: :number, data: content }], max_size: 22, level: :l) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
7 8 9 |
# File 'lib/health_cards/chunk.rb', line 7 def data @data end |
#ordinal ⇒ Object (readonly)
Returns the value of attribute ordinal.
7 8 9 |
# File 'lib/health_cards/chunk.rb', line 7 def ordinal @ordinal end |
#qrcode ⇒ Object (readonly)
Returns the value of attribute qrcode.
7 8 9 |
# File 'lib/health_cards/chunk.rb', line 7 def qrcode @qrcode end |
Instance Method Details
#image ⇒ Object
28 29 30 |
# File 'lib/health_cards/chunk.rb', line 28 def image @qrcode.as_png(module_px_size: 2) end |
#qr_code ⇒ Object
24 25 26 |
# File 'lib/health_cards/chunk.rb', line 24 def qr_code @qrcode.qrcode end |