Permalink
Browse files

1.9 compatible

  • Loading branch information...
Mason
Mason committed May 8, 2011
1 parent 115be99 commit 83b0ec61276eed2ba3cd52dc704ac568888e4401
Showing with 35 additions and 46 deletions.
  1. +1 −1 LICENSE
  2. +2 −14 README.rdoc
  3. +1 −1 fasterer-csv.gemspec
  4. +11 −10 lib/fasterer_csv.rb
  5. +20 −20 spec/fasterer_csv_spec.rb
View
@@ -1,3 +1,3 @@
-Mockyright (m) 2010 Mason
+Monkeyright (m) 2010 Mason
Permission is hereby granted.
View
@@ -6,21 +6,9 @@ Depends on various stuff and such it almost always reads at least twice as fast,
It's got some caveats, though... which you'll discover in fun and entertaining ways.
-Also, it's not *completely* a drop in replacement, but it's really really close. Why do it this way? Because I hate you and want to make you life a little more difficult whenever possible.
+Also, it's not *completely* a drop in replacement, but it's really really close. Why do it this way? To be contrary.
-
-== Note on Patches/Pull Requests
-
-* Spoon the project.
-* Make your feature addition or bug fix.
-* Add tests for it. This is important so I don't break it in a
- future version unintentionally.
-* Commit, do not mess with rakefile, version, or history.
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-* Send me a pull request.
-* Delete everything you've done at the point because I'm probably going to reimplement it anyways.
-
-== Monkyright
+== Monkeyright
Monkeyright (m) 2010 Mason. See LICENSE for details.
View
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{fasterer-csv}
- s.version = "1.6.0"
+ s.version = "2.0.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Mason"]
View
@@ -159,6 +159,7 @@ def []=(key, val)
def pull(*columns)
columns.map do |column|
+ column = [nil] if column.nil?
self[*column]
end
end
@@ -221,13 +222,13 @@ def clear
end
def <<(ch)
- if ch == ?-
+ if ch == ?-.ord
@float = @int = size == 0
- elsif (ch > ?9 || ch < ?0) && ch != ?.
+ elsif (ch > ?9.ord || ch < ?0.ord) && ch != ?..ord
@int = @float = false
- elsif ch == ?. && @dot
+ elsif ch == ?..ord && @dot
@int = @float = false
- elsif ch == ?.
+ elsif ch == ?..ord
@int = false
@dot = true
end
@@ -304,21 +305,21 @@ def parse_headers(data, quot = '~', sep = ',', fail_on_malformed = true, column
end
def parse(data, quot = '~', sep = ',', fail_on_malformed = true, column = NoConversion.new)
- q, s, row, inquot, clean, maybe, table, field, endline = quot[0], sep[0], [], false, true, false, nil, true, false
+ q, s, row, inquot, clean, maybe, table, field, endline = quot.ord, sep.ord, [], false, true, false, nil, true, false
data.each_byte do |c|
- next if c == ?\r
+ next if c == ?\r.ord
if maybe && c == s
row << column.convert(true)
column.clear
clean, inquot, maybe, field, endline = true, false, false, true, false
- elsif maybe && c == ?\n && table.nil?
+ elsif maybe && c == ?\n.ord && table.nil?
row << column.convert(true) unless (column.empty? && endline)
column.clear
table = Table.new(row, fail_on_malformed) unless row.empty?
row, clean, inquot, maybe, field, endline = [], true, false, false, false, true
- elsif maybe && c == ?\n
+ elsif maybe && c == ?\n.ord
row << column.convert(true) unless (column.empty? && endline)
column.clear
table << row unless row.empty?
@@ -337,14 +338,14 @@ def parse(data, quot = '~', sep = ',', fail_on_malformed = true, column = NoConv
row << column.convert(false)
column.clear
clean, field, endline = true, true, false
- elsif c == ?\n && table.nil?
+ elsif c == ?\n.ord && table.nil?
row << column.convert(false) unless column.empty? && endline
column.clear
table = Table.new(row, fail_on_malformed) unless row.empty?
row, clean, inquot, field, endline = [], true, false, false, true
- elsif c == ?\n
+ elsif c == ?\n.ord
row << column.convert(false) unless column.empty? && endline
View
@@ -21,45 +21,45 @@
it "works" do
conv = FastererCSV::NumericConversion.new
- conv << ?1
+ conv << ?1.ord
conv.convert(true).class.should == String
conv.convert(true).should == "1"
conv.convert(false).class.should == Fixnum
conv.convert(false).should == 1
conv.clear
- conv << ?-
- conv << ?1
+ conv << ?-.ord
+ conv << ?1.ord
conv.convert(false).class.should == Fixnum
conv.convert(false).should == -1
conv.clear
- conv << ?1
- conv << ?.
- conv << ?1
+ conv << ?1.ord
+ conv << ?..ord
+ conv << ?1.ord
conv.convert(false).class.should == Float
conv.convert(false).should == 1.1
conv.clear
- conv << ?-
- conv << ?1
- conv << ?.
- conv << ?1
+ conv << ?-.ord
+ conv << ?1.ord
+ conv << ?..ord
+ conv << ?1.ord
conv.convert(false).class.should == Float
conv.convert(false).should == -1.1
conv.clear
- conv << ?1
- conv << ?.
- conv << ?1
- conv << ?.
- conv << ?1
+ conv << ?1.ord
+ conv << ?..ord
+ conv << ?1.ord
+ conv << ?..ord
+ conv << ?1.ord
conv.convert(false).class.should == String
conv.convert(false).should == "1.1.1"
conv.clear
- conv << ?a
+ conv << ?a.ord
conv.convert(false).class.should == String
conv.convert(false).should == "a"
@@ -74,7 +74,7 @@
it "works" do
conv = FastererCSV::NoConversion.new
- conv << ?1
+ conv << ?1.ord
conv.convert(true).class.should == String
conv.convert(false).class.should == String
@@ -105,11 +105,11 @@
describe "parse" do
it "works" do
table = FastererCSV.parse(@data)
- table.headers.should == [:a, :b, :c,:d,:e,:f,:g,:h,:i,:j,:k,:l,:m,:_]
+ table.headers.should == [:a, :b, :c, :d, :e, :f, :g, :h, :i, :j, :k, :l, :m, :_]
table.lines.should == 2
- table[0].should == [nil, nil, "1", "1.1", "-1", "-1.1", "1.1.1", "1", "a", "a", "a~a", "a\n~a", ",", nil]
- table[1].should == ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "14"]
+ table[0].should == [nil, nil, "1", "1.1", "-1", "-1.1", "1.1.1", "1", "a", "a", "a~a", "a\n~a", ",", nil ]
+ table[1].should == ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "14"]
row = table[1]
row.pull(:a, nil, 'd').should == ["0","14","3"]

0 comments on commit 83b0ec6

Please sign in to comment.