Class: Skyfall::Label
- Inherits:
-
Object
- Object
- Skyfall::Label
- Defined in:
- lib/skyfall/label.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #authority ⇒ Object (also: #src)
- #cid ⇒ Object
- #created_at ⇒ Object (also: #cts)
- #expires_at ⇒ Object (also: #exp)
-
#initialize(data) ⇒ Label
constructor
A new instance of Label.
- #negation? ⇒ Boolean (also: #neg)
- #subject ⇒ Object (also: #uri)
- #value ⇒ Object (also: #val)
- #version ⇒ Object (also: #ver)
Constructor Details
#initialize(data) ⇒ Label
Returns a new instance of Label.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/skyfall/label.rb', line 8 def initialize(data) @data = data raise DecodeError.new("Missing version: #{data}") unless data.has_key?('ver') raise DecodeError.new("Invalid version: #{ver}") unless ver.is_a?(Integer) && ver >= 1 raise UnsupportedError.new("Unsupported version: #{ver}") unless ver == 1 raise DecodeError.new("Missing source: #{data}") unless data.has_key?('src') raise DecodeError.new("Invalid source: #{src}") unless src.is_a?(String) && src.start_with?('did:') raise DecodeError.new("Missing uri: #{data}") unless data.has_key?('uri') raise DecodeError.new("Invalid uri: #{uri}") unless uri.is_a?(String) raise DecodeError.new("Invalid uri: #{uri}") unless uri.start_with?('at://') || uri.start_with?('did:') end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
6 7 8 |
# File 'lib/skyfall/label.rb', line 6 def data @data end |
Instance Method Details
#authority ⇒ Object Also known as: src
27 28 29 |
# File 'lib/skyfall/label.rb', line 27 def @data['src'] end |
#cid ⇒ Object
35 36 37 |
# File 'lib/skyfall/label.rb', line 35 def cid @cid ||= @data['cid'] && CID.from_json(@data['cid']) end |
#created_at ⇒ Object Also known as: cts
47 48 49 |
# File 'lib/skyfall/label.rb', line 47 def created_at @created_at ||= Time.parse(@data['cts']) end |
#expires_at ⇒ Object Also known as: exp
51 52 53 |
# File 'lib/skyfall/label.rb', line 51 def expires_at @expires_at ||= @data['exp'] && Time.parse(@data['exp']) end |
#negation? ⇒ Boolean Also known as: neg
43 44 45 |
# File 'lib/skyfall/label.rb', line 43 def negation? !!@data['neg'] end |
#subject ⇒ Object Also known as: uri
31 32 33 |
# File 'lib/skyfall/label.rb', line 31 def subject @data['uri'] end |
#value ⇒ Object Also known as: val
39 40 41 |
# File 'lib/skyfall/label.rb', line 39 def value @data['val'] end |
#version ⇒ Object Also known as: ver
23 24 25 |
# File 'lib/skyfall/label.rb', line 23 def version @data['ver'] end |