Class: HealthCards::HealthCard
- Inherits:
-
Object
- Object
- HealthCards::HealthCard
- Extended by:
- Forwardable
- Defined in:
- lib/health_cards/health_card.rb
Overview
Represents a signed SMART Health Card
Instance Attribute Summary collapse
-
#jws ⇒ Object
readonly
Returns the value of attribute jws.
Instance Method Summary collapse
-
#initialize(jws) ⇒ HealthCard
constructor
Create a HealthCard from a JWS.
-
#qr_codes ⇒ Array<Chunk>
QR Codes representing this HealthCard.
-
#resource(type: nil, &block) ⇒ Object
Extracts a resource from the bundle contained in the HealthCard.
-
#resources(type: nil, &block) ⇒ Object
Extracts all resources from the bundle contained in the HealthCard.
-
#to_json(*_args) ⇒ String
Export HealthCard as JSON, formatted for file downloads.
Constructor Details
#initialize(jws) ⇒ HealthCard
Create a HealthCard from a JWS
15 16 17 18 19 |
# File 'lib/health_cards/health_card.rb', line 15 def initialize(jws) @jws = JWS.from_jws(jws) @payload = Payload.from_payload(@jws.payload) @qr_codes = QRCodes.from_jws(@jws) end |
Instance Attribute Details
#jws ⇒ Object (readonly)
Returns the value of attribute jws.
8 9 10 |
# File 'lib/health_cards/health_card.rb', line 8 def jws @jws end |
Instance Method Details
#qr_codes ⇒ Array<Chunk>
QR Codes representing this HealthCard
29 30 31 |
# File 'lib/health_cards/health_card.rb', line 29 def qr_codes @qr_codes.chunks end |
#resource(type: nil, &block) ⇒ Object
Extracts a resource from the bundle contained in the HealthCard. A filter can be applied by using a block. The method will yield each resource to the block. The block should return a boolean
38 39 40 |
# File 'lib/health_cards/health_card.rb', line 38 def resource(type: nil, &block) resources(type: type, &block).first end |
#resources(type: nil, &block) ⇒ Object
Extracts all resources from the bundle contained in the HealthCard. A filter can be applied by using a block. The method will yield each resource to the block. The block should return a boolean
47 48 49 50 51 52 53 54 |
# File 'lib/health_cards/health_card.rb', line 47 def resources(type: nil, &block) all_resources = bundle.entry.map(&:resource) return all_resources unless type || block all_resources.filter do |r| resource_matches_criteria(r, type, &block) end end |
#to_json(*_args) ⇒ String
Export HealthCard as JSON, formatted for file downloads
23 24 25 |
# File 'lib/health_cards/health_card.rb', line 23 def to_json(*_args) Exporter.file_download([@jws]) end |