Class: NWN::TwoDA::Row

Inherits:
Array
  • Object
show all
Defined in:
lib/nwn/twoda.rb

Overview

A Row is simply an Array with some helpers. It wraps a data row in a TwoDA::Table.

You can access Table columns in a row by simply calling a method with the same name.

For example (spells.2da):

table.rows.select {|x| x.Wiz_Sorc == "9" }

selects all level 9 arcane spells.

Instance Attribute Summary collapse

Attributes inherited from Array

#to_yaml_style

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/nwn/twoda.rb', line 43

def method_missing meth, *args
  if idx = @table.columns.index(meth.to_s.downcase) || idx = @table.columns.index(meth.to_s)
    if meth.to_s =~ /=$/
      self[idx] = args.shift or raise ArgumentError,
        "Need a paramenter for assignments .."
    else
      self[idx]
    end
  else
    super
  end
end

Instance Attribute Details

#tableObject

Returns the value of attribute table.



36
37
38
# File 'lib/nwn/twoda.rb', line 36

def table
  @table
end

Instance Method Details

#IDObject

Returns the id of this row.



39
40
41
# File 'lib/nwn/twoda.rb', line 39

def ID
  @table.rows.index(self)
end