Class: Lumb::Entry
- Inherits:
-
Object
- Object
- Lumb::Entry
- Defined in:
- lib/lumb/entry.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#ws ⇒ Object
readonly
Returns the value of attribute ws.
Instance Method Summary collapse
-
#initialize(structure, items, ws) ⇒ Entry
constructor
A new instance of Entry.
- #slot(name) ⇒ Object
Constructor Details
#initialize(structure, items, ws) ⇒ Entry
Returns a new instance of Entry.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/lumb/entry.rb', line 5 def initialize(structure, items, ws) @structure, @items, @ws = structure, items, ws @slots = [] @items.each do |item| @slots[@structure.slot_index(item.slot)] = item.value end @structure.items.each.with_index do |item, idx| if @slots[idx].nil? raise "slot '#{item.slot}' is missing from entry" elsif @slots[idx].type != item.type raise "type mismatch: expected '#{item.type}', got '#{@slots[idx].type}'" end end end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'lib/lumb/entry.rb', line 3 def items @items end |
#ws ⇒ Object (readonly)
Returns the value of attribute ws.
3 4 5 |
# File 'lib/lumb/entry.rb', line 3 def ws @ws end |
Instance Method Details
#slot(name) ⇒ Object
22 23 24 |
# File 'lib/lumb/entry.rb', line 22 def slot(name) @slots[@structure.slot_index(name)] end |