Class: Swak::Table::SmartRow
Instance Attribute Summary collapse
-
#colmap ⇒ Object
readonly
Returns the value of attribute colmap.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
- #[](*args) ⇒ Object
- #[]=(*args) ⇒ Object
-
#initialize(header, fields) ⇒ SmartRow
constructor
A new instance of SmartRow.
- #method_missing(sym, *args, &block) ⇒ Object
Constructor Details
#initialize(header, fields) ⇒ SmartRow
Returns a new instance of SmartRow.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/swak/table.rb', line 6 def initialize(header, fields) if header.size != fields.size raise "Header and field size mismatch in SmartRow.new #{header.inspect} vs #{fields.inspect}" end @header = header @fields = fields @colmap = {} header.each_with_index {|fieldname, i| @colmap[fieldname] = i} if @colmap.size != @header.size raise "Duplicate field names not allowed in SmartRow header" end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object
36 37 38 |
# File 'lib/swak/table.rb', line 36 def method_missing(sym, *args, &block) @fields.send(sym, *args, &block) end |
Instance Attribute Details
#colmap ⇒ Object (readonly)
Returns the value of attribute colmap.
4 5 6 |
# File 'lib/swak/table.rb', line 4 def colmap @colmap end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
4 5 6 |
# File 'lib/swak/table.rb', line 4 def fields @fields end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
4 5 6 |
# File 'lib/swak/table.rb', line 4 def header @header end |