Skip to content

Instantly share code, notes, and snippets.

@dux
Created May 21, 2012 01:53
Show Gist options
  • Save dux/2760251 to your computer and use it in GitHub Desktop.
Save dux/2760251 to your computer and use it in GitHub Desktop.
Simple CSV class
#!/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