Class: Skyfall::Label

Inherits:
Object
  • Object
show all
Defined in:
lib/skyfall/label.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Label

Returns a new instance of Label.

Raises:



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

#dataObject (readonly)

Returns the value of attribute data.



6
7
8
# File 'lib/skyfall/label.rb', line 6

def data
  @data
end

Instance Method Details

#authorityObject Also known as: src



27
28
29
# File 'lib/skyfall/label.rb', line 27

def authority
  @data['src']
end

#cidObject



35
36
37
# File 'lib/skyfall/label.rb', line 35

def cid
  @cid ||= @data['cid'] && CID.from_json(@data['cid'])
end

#created_atObject 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_atObject 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

Returns:

  • (Boolean)


43
44
45
# File 'lib/skyfall/label.rb', line 43

def negation?
  !!@data['neg']
end

#subjectObject Also known as: uri



31
32
33
# File 'lib/skyfall/label.rb', line 31

def subject
  @data['uri']
end

#valueObject Also known as: val



39
40
41
# File 'lib/skyfall/label.rb', line 39

def value
  @data['val']
end

#versionObject Also known as: ver



23
24
25
# File 'lib/skyfall/label.rb', line 23

def version
  @data['ver']
end