Class: HealthCards::QRCodes
- Inherits:
-
Object
- Object
- HealthCards::QRCodes
- Defined in:
- lib/health_cards/qr_codes.rb
Overview
Implements QR Code chunking in ruby
Instance Attribute Summary collapse
-
#chunks ⇒ Object
readonly
Returns the value of attribute chunks.
Class Method Summary collapse
-
.from_jws(jws) ⇒ HealthCards::QRCodes
Creates a QRCodes from a JWS.
Instance Method Summary collapse
-
#code_by_ordinal(num) ⇒ HealthCards::Chunk
Find a single QR Code chunk from this collection based on its ordinal position.
-
#initialize(chunks) ⇒ QRCodes
constructor
Creates a QRCodes from a set of encoded chunks.
-
#to_jws ⇒ HealthCards::JWS
Combine all chunks and decodes it into a JWS object.
Constructor Details
Instance Attribute Details
#chunks ⇒ Object (readonly)
Returns the value of attribute chunks.
8 9 10 |
# File 'lib/health_cards/qr_codes.rb', line 8 def chunks @chunks end |
Class Method Details
.from_jws(jws) ⇒ HealthCards::QRCodes
Creates a QRCodes from a JWS
13 14 15 |
# File 'lib/health_cards/qr_codes.rb', line 13 def self.from_jws(jws) QRCodes.new(ChunkingUtils.jws_to_qr_chunks(jws.to_s)) end |
Instance Method Details
#code_by_ordinal(num) ⇒ HealthCards::Chunk
Find a single QR Code chunk from this collection based on its ordinal position
25 26 27 |
# File 'lib/health_cards/qr_codes.rb', line 25 def code_by_ordinal(num) chunks.find { |ch| ch.ordinal == num } end |
#to_jws ⇒ HealthCards::JWS
Combine all chunks and decodes it into a JWS object
31 32 33 34 |
# File 'lib/health_cards/qr_codes.rb', line 31 def to_jws jws_string = ChunkingUtils.qr_chunks_to_jws(chunks.map(&:data)) JWS.from_jws(jws_string) end |