Created
May 21, 2012 01:53
-
-
Save dux/2760251 to your computer and use it in GitHub Desktop.
Simple CSV class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Hotel - broj ratinga - rating - datum - soba1 opis - soba1 cijena - soba2 opis soba 2 cijena | |
require 'rubygems' | |
require 'digest/md5' | |
require 'pp' | |
class Csv | |
attr_accessor :head, :data | |
def initialize(file) | |
@rows = File.read(file).split "\n" | |
@head = @rows.shift.split(';') | |
@data = [] | |
for row in @rows | |
h = {} | |
cnt = -1 | |
for el in row.split(';').map | |
h[@head[cnt += 1].to_sym] = el.sub /^\s+/,'' | |
end | |
@data.push h | |
end | |
end | |
end | |
for el in Csv.new('imenik.csv').data | |
pp el[:email2] if el[:email2].to_s.length > 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment