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

Returns a new instance of Row.



277
278
279
280
# File 'lib/windy.rb', line 277

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



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

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.



275
276
277
# File 'lib/windy.rb', line 275

def collection
  @collection
end

#valuesObject (readonly)

Returns the value of attribute values.



275
276
277
# File 'lib/windy.rb', line 275

def values
  @values
end

Instance Method Details

#[](index_or_name) ⇒ Object



282
283
284
285
286
287
288
# File 'lib/windy.rb', line 282

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



307
308
309
# File 'lib/windy.rb', line 307

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

#lengthObject



299
300
301
# File 'lib/windy.rb', line 299

def length
  values.length
end

#to_aObject



303
304
305
# File 'lib/windy.rb', line 303

def to_a
  values
end