Class: SQLite::Row
- Inherits:
-
Object
- Object
- SQLite::Row
- Defined in:
- lib/sqlite.rb
Overview
Row/Recordset classes to simplify running queries
Instance Method Summary collapse
- #[](index) ⇒ Object
- #each ⇒ Object
- #hashify ⇒ Object
-
#initialize(rowset, row) ⇒ Row
constructor
A new instance of Row.
- #keys ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(rowset, row) ⇒ Row
Returns a new instance of Row.
69 70 71 72 |
# File 'lib/sqlite.rb', line 69 def initialize(rowset, row) @rowset = rowset @row = row end |
Instance Method Details
#[](index) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/sqlite.rb', line 99 def [](index) # If column name if index.class == String # Convert to ordinal index = @rowset.header_indexes[index] end if index != nil return @rowset.data[@row][index] end end |
#each ⇒ Object
82 83 84 85 86 87 |
# File 'lib/sqlite.rb', line 82 def each data = @rowset.data[@row] 0.upto(data.size()-1) do |i| yield @rowset.header_names[i], data[i] end end |
#hashify ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/sqlite.rb', line 89 def hashify() hash = {} self.each do |k,v| hash[k] = v end return hash end |
#keys ⇒ Object
74 75 76 |
# File 'lib/sqlite.rb', line 74 def keys() return @rowset.columns end |
#values ⇒ Object
78 79 80 |
# File 'lib/sqlite.rb', line 78 def values() return @rowset.data[@row] end |