Class: Lumb::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/lumb/entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#itemsObject (readonly)

Returns the value of attribute items.



3
4
5
# File 'lib/lumb/entry.rb', line 3

def items
  @items
end

#wsObject (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