Class: AsciiMath::SymbolTableBuilder
- Inherits:
-
Object
- Object
- AsciiMath::SymbolTableBuilder
- Defined in:
- lib/asciimath/symbol_table.rb
Instance Method Summary collapse
- #add(*args) ⇒ Object
- #build ⇒ Object
-
#initialize(allow_symbol_overwrites: true) ⇒ SymbolTableBuilder
constructor
A new instance of SymbolTableBuilder.
Constructor Details
#initialize(allow_symbol_overwrites: true) ⇒ SymbolTableBuilder
Returns a new instance of SymbolTableBuilder.
3 4 5 6 |
# File 'lib/asciimath/symbol_table.rb', line 3 def initialize(allow_symbol_overwrites: true) @table = {} @allow_symbol_overwrites = allow_symbol_overwrites end |
Instance Method Details
#add(*args) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/asciimath/symbol_table.rb', line 8 def add(*args) raise 'Insufficient arguments' if args.length < 3 entry = {} if args.last.is_a?(Hash) entry.merge!(args.pop) end entry[:type] = args.pop entry[:value] = args.pop entry.freeze args.map(&:freeze).each do |name| raise "Symbol overwrites are disallowed, but were attempted for #{name}" if !@allow_symbol_overwrites && !@table[name].nil? @table[name] = entry end end |
#build ⇒ Object
26 27 28 |
# File 'lib/asciimath/symbol_table.rb', line 26 def build @table.dup.freeze end |