Class: GtfsReader::FileRow
- Inherits:
-
Object
- Object
- GtfsReader::FileRow
- Defined in:
- lib/gtfs_reader/file_row.rb
Overview
Contains the contents of a single row read in from the file
Instance Attribute Summary collapse
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
Instance Method Summary collapse
-
#[](column) ⇒ Object
The parsed data for the column at this row.
- #headers ⇒ Array<Symbol>
- #initialize(line_number, headers, data, definition, do_parse) ⇒ Array<Symbol> constructor
-
#raw(column) ⇒ Object
The data unparsed data from the column at this row.
-
#to_a ⇒ Array
An array representing this row of data.
-
#to_hash ⇒ Hash
A hash representing this row of data, where each key is the column name and each value is the parsed data for this row.
Constructor Details
#initialize(line_number, headers, data, definition, do_parse) ⇒ Array<Symbol>
13 14 15 16 17 |
# File 'lib/gtfs_reader/file_row.rb', line 13 def initialize(line_number, headers, data, definition, do_parse) @line_number, @headers, @data, @definition, @do_parse = line_number, headers, data, definition, do_parse @parsed = {} end |
Instance Attribute Details
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
6 7 8 |
# File 'lib/gtfs_reader/file_row.rb', line 6 def line_number @line_number end |
Instance Method Details
#[](column) ⇒ Object
Returns the parsed data for the column at this row.
27 28 29 30 31 32 33 34 |
# File 'lib/gtfs_reader/file_row.rb', line 27 def [](column) return raw(column) unless @do_parse @parsed[column] ||= begin ParserContext.new(column, self). instance_exec raw(column), &@definition[column].parser end end |
#headers ⇒ Array<Symbol>
20 21 22 |
# File 'lib/gtfs_reader/file_row.rb', line 20 def headers @headers end |
#raw(column) ⇒ Object
Returns the data unparsed data from the column at this row.
38 39 40 |
# File 'lib/gtfs_reader/file_row.rb', line 38 def raw(column) @data[column] end |
#to_a ⇒ Array
Returns an array representing this row of data.
49 50 51 |
# File 'lib/gtfs_reader/file_row.rb', line 49 def to_a headers.map {|h| self[h] } end |
#to_hash ⇒ Hash
Returns a hash representing this row of data, where each key is the column name and each value is the parsed data for this row.
44 45 46 |
# File 'lib/gtfs_reader/file_row.rb', line 44 def to_hash ::Hash[ *headers.inject([]) {|list,h| list << h << self[h] } ] end |