Class: Skyfall::CID
- Inherits:
-
Object
- Object
- Skyfall::CID
- Defined in:
- lib/skyfall/cid.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(data) ⇒ CID
constructor
A new instance of CID.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(data) ⇒ CID
Returns a new instance of CID.
27 28 29 |
# File 'lib/skyfall/cid.rb', line 27 def initialize(data) @data = data end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/skyfall/cid.rb', line 11 def data @data end |
Class Method Details
.from_cbor_tag(tag) ⇒ Object
13 14 15 16 17 |
# File 'lib/skyfall/cid.rb', line 13 def self.from_cbor_tag(tag) data = tag.value raise DecodeError.new("Unexpected first byte of CID: #{data[0]}") unless data[0] == "\x00" CID.new(data[1..-1]) end |
.from_json(string) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/skyfall/cid.rb', line 19 def self.from_json(string) raise DecodeError.new("Unexpected CID length") unless string.length == 59 raise DecodeError.new("Unexpected CID prefix") unless string[0] == 'b' data = Base32.decode(string[1..-1].upcase) CID.new(data) end |
Instance Method Details
#==(other) ⇒ Object
39 40 41 |
# File 'lib/skyfall/cid.rb', line 39 def ==(other) other.is_a?(CID) && @data == other.data end |
#inspect ⇒ Object
35 36 37 |
# File 'lib/skyfall/cid.rb', line 35 def inspect "CID(\"#{to_s}\")" end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/skyfall/cid.rb', line 31 def to_s 'b' + Base32.encode(@data).downcase.gsub(/=+$/, '') end |