Skip to content

Instantly share code, notes, and snippets.

@bjhaid
Created February 23, 2012 17:55
Show Gist options
  • Save bjhaid/1894034 to your computer and use it in GitHub Desktop.
Save bjhaid/1894034 to your computer and use it in GitHub Desktop.
Ruby code:
require 'csv'
class Phonecsvtoarray
attr_accessor :arr_path
def csv_to_array
arr = []
CSV.foreach(@arr_path) do |row|
arr << row
end
#r = /(^0\d{8,10}$)/
r = /^0[^0](\d{7,9}$)/
x = []
arr.flatten!
arr.each {|w| (x << w.strip!) if r.match(w.strip)}
x.delete(nil)
x
end
end
a = Phonecsvtoarray.new
a.arr_path = "./a.csv"
p a.csv_to_array
bjhaid@bjhaid-HP-Pavilion-dm4-Notebook-PC ~/Desktop $ export CLASSPATH=/home/bjhaid/.rvm/rubies/jruby-1.6.5/lib/jruby.jar:~/Desktop
bjhaid@bjhaid-HP-Pavilion-dm4-Notebook-PC ~/Desktop $ jrubyc phonecsvtoarray.rb
bjhaid@bjhaid-HP-Pavilion-dm4-Notebook-PC ~/Desktop $ java phonecsvtoarray
Exception in thread "main" org.jruby.exceptions.RaiseException: (LoadError) no such file to load -- csv
at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1038)
at phonecsvtoarray.(root)(phonecsvtoarray.rb:5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment