Class: Lumb::Structure

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(items, ws) ⇒ Structure

Returns a new instance of Structure.



5
6
7
8
9
10
11
12
# File 'lib/lumb/structure.rb', line 5

def initialize(items, ws)
  @items, @ws = items, ws

  @slots = {}
  @items.map.with_index do |item, idx|
    @slots[item.slot] = idx
  end
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



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

def items
  @items
end

#wsObject (readonly)

Returns the value of attribute ws.



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

def ws
  @ws
end

Instance Method Details

#slot_index(name) ⇒ Object



14
15
16
# File 'lib/lumb/structure.rb', line 14

def slot_index(name)
  @slots[name.to_sym]
end

#slot_type(name_or_index) ⇒ Object



18
19
20
21
# File 'lib/lumb/structure.rb', line 18

def slot_type(name_or_index)
  name_or_index = slot_index(name_or_index) unless name_or_index.is_a? Fixnum
  @items[name_or_index].type
end