Class: Opencdd::AliasTable
- Inherits:
-
Object
- Object
- Opencdd::AliasTable
- Defined in:
- lib/opencdd/alias_table.rb
Constant Summary collapse
- DUPLICATE_ALIAS =
"duplicate alias: %<name>s"
Instance Method Summary collapse
- #declare(alias_name, property_id) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(defaults: true) ⇒ AliasTable
constructor
A new instance of AliasTable.
- #key?(name) ⇒ Boolean
- #redeclare(alias_name, property_id) ⇒ Object
- #resolve(name) ⇒ Object
- #size ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(defaults: true) ⇒ AliasTable
Returns a new instance of AliasTable.
7 8 9 |
# File 'lib/opencdd/alias_table.rb', line 7 def initialize(defaults: true) @table = defaults ? PropertyIds.alias_map.dup : {} end |
Instance Method Details
#declare(alias_name, property_id) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/opencdd/alias_table.rb', line 11 def declare(alias_name, property_id) name = alias_name.to_s existing = @table[name] if existing if existing == property_id.to_s return self end raise ArgumentError, format(DUPLICATE_ALIAS, name: name) end raise ArgumentError, "unknown property id: #{property_id}" unless PropertyIds.entry(property_id) @table[name] = property_id.to_s self end |
#each(&block) ⇒ Object
40 41 42 |
# File 'lib/opencdd/alias_table.rb', line 40 def each(&block) @table.each(&block) end |
#key?(name) ⇒ Boolean
36 37 38 |
# File 'lib/opencdd/alias_table.rb', line 36 def key?(name) @table.key?(name.to_s) end |
#redeclare(alias_name, property_id) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/opencdd/alias_table.rb', line 25 def redeclare(alias_name, property_id) name = alias_name.to_s raise ArgumentError, "unknown property id: #{property_id}" unless PropertyIds.entry(property_id) @table[name] = property_id.to_s self end |
#resolve(name) ⇒ Object
32 33 34 |
# File 'lib/opencdd/alias_table.rb', line 32 def resolve(name) @table[name.to_s] end |
#size ⇒ Object
48 49 50 |
# File 'lib/opencdd/alias_table.rb', line 48 def size @table.size end |
#to_h ⇒ Object
44 45 46 |
# File 'lib/opencdd/alias_table.rb', line 44 def to_h @table.dup end |