Class: Dillo::Row

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, values) ⇒ Row

Returns a new instance of Row.



278
279
280
281
# File 'lib/dillo.rb', line 278

def initialize(collection, values)
  @collection = collection
  @values = values
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



291
292
293
294
295
296
297
298
# File 'lib/dillo.rb', line 291

def method_missing(method, *args, &block)
  name = method.to_s.gsub('_', ' ')
  if collection.column_index(name)
    self[name]
  else
    super
  end
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



276
277
278
# File 'lib/dillo.rb', line 276

def collection
  @collection
end

#valuesObject (readonly)

Returns the value of attribute values.



276
277
278
# File 'lib/dillo.rb', line 276

def values
  @values
end

Instance Method Details

#[](index_or_name) ⇒ Object



283
284
285
286
287
288
289
# File 'lib/dillo.rb', line 283

def [](index_or_name)
  if index_or_name.is_a?(Integer)
    values[index_or_name]
  elsif index = collection.column_index(index_or_name)
    values[index]
  end
end

#inspectObject



308
309
310
# File 'lib/dillo.rb', line 308

def inspect
  "#<#{self.class.name} #{values.inspect}>"
end

#lengthObject



300
301
302
# File 'lib/dillo.rb', line 300

def length
  values.length
end

#to_aObject



304
305
306
# File 'lib/dillo.rb', line 304

def to_a
  values
end