Class: HiveMeta::Record
- Inherits:
-
Object
- Object
- HiveMeta::Record
- Defined in:
- lib/hivemeta/record.rb
Instance Method Summary collapse
- #[](index) ⇒ Object
-
#_count ⇒ Object
(also: #_size, #_length)
avoid collisions with column name ‘count’ ugly :(.
-
#initialize(line, table, opts = {}) ⇒ Record
constructor
A new instance of Record.
-
#method_missing(id, *args) ⇒ Object
allow for column access via column name as a method example: rec.col_name.
Constructor Details
#initialize(line, table, opts = {}) ⇒ Record
Returns a new instance of Record.
6 7 8 9 10 11 12 13 |
# File 'lib/hivemeta/record.rb', line 6 def initialize(line, table, opts = {}) @fields = line.chomp.split(table.delimiter, -1) if @fields.size != table.columns.size raise FieldCountError if not opts[:ignore_field_count] end @table = table end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args) ⇒ Object
allow for column access via column name as a method example: rec.col_name
36 37 38 39 40 |
# File 'lib/hivemeta/record.rb', line 36 def method_missing(id, *args) return @fields[@table.indexes[id]] rescue raise NoMethodError end |
Instance Method Details
#[](index) ⇒ Object
29 30 31 32 |
# File 'lib/hivemeta/record.rb', line 29 def [] index return "#{@fields[index]}" if index.is_a? Integer "#{@fields[@table.indexes[index.to_sym]]}" end |
#_count ⇒ Object Also known as: _size, _length
avoid collisions with column name ‘count’ ugly :(
17 18 19 |
# File 'lib/hivemeta/record.rb', line 17 def _count @fields.count end |