Class: ZATCA::Tags
- Inherits:
-
Object
- Object
- ZATCA::Tags
- Defined in:
- lib/zatca/tags.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#initialize(tags) ⇒ Tags
constructor
A new instance of Tags.
- #to_base64 ⇒ Object
-
#to_hex_tlv ⇒ Object
This is helpful for debugging only, for ZATCA’s requirements just call ‘to_base64`.
-
#to_tlv ⇒ Object
This is helpful for debugging only, for ZATCA’s requirements just call ‘to_base64`.
Constructor Details
#initialize(tags) ⇒ Tags
Returns a new instance of Tags.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/zatca/tags.rb', line 5 def initialize() keys_to_coerce_to_string = .except(:timestamp).keys = .map do |key, value| if keys_to_coerce_to_string.include?(key) [key, value.to_s] else [key, value] end end.to_h schema_result = TagsSchema.call() if schema_result.failure? raise(Error, "Parsing tags failed due to:\n#{schema_result.errors(full: true).to_h}") end [:timestamp] = [:timestamp].to_s # Create tags, then sort them by ID @tags = .map do |key, value| Tag.new(key: key, value: value) end.sort_by(&:id) end |
Instance Method Details
#[](index) ⇒ Object
28 29 30 |
# File 'lib/zatca/tags.rb', line 28 def [](index) @tags[index] end |
#to_base64 ⇒ Object
32 33 34 |
# File 'lib/zatca/tags.rb', line 32 def to_base64 Base64.strict_encode64(to_tlv) end |
#to_hex_tlv ⇒ Object
This is helpful for debugging only, for ZATCA’s requirements just call ‘to_base64`
37 38 39 |
# File 'lib/zatca/tags.rb', line 37 def to_hex_tlv to_tlv.unpack1("H*") end |
#to_tlv ⇒ Object
This is helpful for debugging only, for ZATCA’s requirements just call ‘to_base64`
42 43 44 |
# File 'lib/zatca/tags.rb', line 42 def to_tlv @tags.map(&:to_tlv).join("") end |