Class: Windy::Row

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, values) ⇒ Row



265
266
267
268
# File 'lib/windy.rb', line 265

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



278
279
280
281
282
283
284
285
# File 'lib/windy.rb', line 278

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.



263
264
265
# File 'lib/windy.rb', line 263

def collection
  @collection
end

#valuesObject (readonly)

Returns the value of attribute values.



263
264
265
# File 'lib/windy.rb', line 263

def values
  @values
end

Instance Method Details

#[](index_or_name) ⇒ Object



270
271
272
273
274
275
276
# File 'lib/windy.rb', line 270

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



295
296
297
# File 'lib/windy.rb', line 295

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

#lengthObject



287
288
289
# File 'lib/windy.rb', line 287

def length
  values.length
end

#to_aObject



291
292
293
# File 'lib/windy.rb', line 291

def to_a
  values
end