Class: DefinensCSV
- Inherits:
-
Object
- Object
- DefinensCSV
- Defined in:
- lib/semicolon_cleaner.rb
Overview
Cleaning of the Definines semicolon junk
Instance Method Summary collapse
- #_digest_utf ⇒ Object
-
#_parse_semicolon ⇒ Object
replaces ; from definins csv with ,.
- #get_dictionary ⇒ Object
-
#initialize(file_path) ⇒ DefinensCSV
constructor
A new instance of DefinensCSV.
- #table ⇒ Object
Constructor Details
#initialize(file_path) ⇒ DefinensCSV
Returns a new instance of DefinensCSV.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/semicolon_cleaner.rb', line 6 def initialize file_path @file_path=file_path @text=File.read @file_path #puts @text.encode("UTF-8") #clean utf not sure why _digest_utf #header_line csv=CSV.read(@file_path) if (csv and csv.count !=0) puts @file_path header=csv[0][0] if header.count(";")>header.count(",") then _parse_semicolon end end #parse_semicolon end |
Instance Method Details
#_digest_utf ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/semicolon_cleaner.rb', line 24 def _digest_utf text=File.read @file_path text=text.encode("UTF-16BE", :invalid=>:replace, :replace=>"?").encode("UTF-8") fh=File.new @file_path, "w" fh.write text fh.close self end |
#_parse_semicolon ⇒ Object
replaces ; from definins csv with ,
34 35 36 37 38 39 40 41 |
# File 'lib/semicolon_cleaner.rb', line 34 def _parse_semicolon #puts "removing semicolons" c=CSV.table @file_path, :col_sep=> ";" fh=File.new @file_path, "w" fh.write c.to_csv fh.close self end |
#get_dictionary ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/semicolon_cleaner.rb', line 47 def get_dictionary table =self.table dictionary={} table.headers.each do |h| dictionary[h]=table[h][0] if table[h] end dictionary end |
#table ⇒ Object
43 44 45 |
# File 'lib/semicolon_cleaner.rb', line 43 def table c=CSV.table @file_path end |