Module: Multicodecs
- Defined in:
- lib/multicodecs.rb,
lib/multicodecs/bare.rb,
lib/multicodecs/version.rb,
lib/multicodecs/registry.rb
Defined Under Namespace
Classes: AutoHashCollection, Registration
Constant Summary
collapse
- VERSION =
'0.2.1'
- REGISTRATIONS =
rubocop:disable Style/MutableConstant
{}
- REGISTRATIONS_PER_TAG =
AutoHashCollection.new
Class Method Summary
collapse
Class Method Details
.[](entry) ⇒ Object
35
36
37
|
# File 'lib/multicodecs/registry.rb', line 35
def [](entry)
find_by(code: entry, name: entry)
end
|
.each(tag: nil) ⇒ Object
76
77
78
79
80
81
82
83
84
|
# File 'lib/multicodecs/registry.rb', line 76
def each(tag: nil)
arr = tag.nil? ? Multicodecs::REGISTRATIONS.values : Multicodecs.where(tag: tag)
if block_given?
return arr.each { |registration| yield registration }
end
arr.each
end
|
.fetch_by!(code: nil, name: nil) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/multicodecs/registry.rb', line 46
def fetch_by!(code: nil, name: nil)
return Multicodecs::REGISTRATIONS.fetch(name) if name
Multicodecs.find_by(code: code).tap do |found|
raise KeyError, "No codec has code #{code}" unless found
end
end
|
.find_by(code: nil, name: nil) ⇒ Object
54
55
56
57
58
|
# File 'lib/multicodecs/registry.rb', line 54
def find_by(code: nil, name: nil)
Multicodecs::REGISTRATIONS.values.find do |v|
v == code || v == name
end
end
|
.load_csv(csv, radix: 16) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/multicodecs/bare.rb', line 9
def load_csv(csv, radix: 16)
csv.each do |row|
name = row['name'] || row[0]
tag = row['tag'] || row[1]
code = row['code'] || row[2]
Multicodecs.register(
name: name.strip,
tag: tag.strip,
code: code.strip.to_i(16)
)
end
end
|
.register(code:, name:, tag:) ⇒ Object