Commit Graph

10 Commits

Author SHA1 Message Date
nahi 6dee0fab9b * lib/csv.rb (CSV.read, CSV.readlines): added. works as IO.read and
IO.readlines in CSV format.

        * lib/csv.rb (CSV.parse): [CAUTION] behavior changed.  in the past,
          CSV.parse accepts a filename to be read-opened (it was just a
          shortcut of CSV.open(filename, 'r')).  now CSV.parse accepts a
          string or a stream to be parsed e.g.
          CSV.parse("1,2\n3,r") #=> [['1', '2'], ['3', '4']]

        * test/csv/test_csv.rb: follow above changes.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-26 14:30:30 +00:00
nahi 406f506d59 * lib/csv.rb: fixed a few bugs around multi char record/field separator.
* test/csv/test_csv.rb: added boundary test for above feature.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6377 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-20 17:24:04 +00:00
nahi 34a553da2e * lib/csv.rb: writes lines with "\n" when row separator is not given.
formerly it was "\r\n".

        * lib/csv.rb: [CAUTION] API change

          * CSV::Row removed.  a row is represented as just an Array.  since
            CSV::Row was a subclass of Array, it won't hurt almost all programs
            except one which depended CSV::Row#match.

          * CSV::Cell removed.  a cell is represented as just a String or
            nil(NULL).  this change will cause widespread destruction.

              CSV.open("foo.csv", "r") do |row|
                row.each do |cell|
                  if cell.is_null       # Cell#is_null
                    p "(NULL)"
                  else
                    p cell.data         # Cell#data
                  end
                end
              end

            must be just;

              CSV.open("foo.csv", "r") do |row|
                row.each do |cell|
                  if cell.nil?
                    p "(NULL)"
                  else
                    p cell
                  end
                end
              end

        * lib/csv.rb: [CAUTION] record separator(CR, LF, CR+LF) behavior
          change.  CSV.open, CSV.parse, and CSV,generate now do not force
          opened file binmode.  formerly it set binmode explicitly.

          with CSV.open, binmode of opened file depends the given mode
          parameter "r", "w", "rb", and "wb".  CSV.parse and CSV.generate open
          file with "r" and "w".

          setting mode properly is user's responsibility now.

        * lib/csv.rb: accepts String as a fs (field separator/column separator)
          and rs (record separator/row separator)

        * lib/csv.rb: added CSV.foreach(path, rs = nil, &block).  CSV.foreach
          now does not handle "| cmd" as a path different from IO.foreach.
          needed?

        * test/csv/test_csv.rb: updated.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6359 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-05-18 12:34:33 +00:00
nobu 92f0be2037 * dln.c, io.c, pack.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb,
lib/date.rb, lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb,
  lib/matrix.rb, lib/monitor.rb, lib/set.rb, lib/thwait.rb,
  lib/timeout.rb, lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb,
  lib/net/ftp.rb, lib/net/http.rb, lib/net/imap.rb, lib/net/pop.rb,
  lib/net/telnet.rb, lib/racc/parser.rb, lib/rinda/rinda.rb,
  lib/rinda/tuplespace.rb, lib/shell/command-processor.rb,
  lib/soap/rpc/soaplet.rb, lib/test/unit/testcase.rb,
  lib/test/unit/testsuite.rb: typo fix.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-18 23:19:47 +00:00
matz 919f456de8 * exception message clean-up by Ian Macdonald <ian@caliban.org>.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6044 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-03-29 07:54:38 +00:00
nahi dd03a2ff20 * lib/csv.rb: document reduction. [ruby-core:02429]
* test/yaml/test_yaml.rb: added 0..1 test with "0".."1" on display.
          it should be defined that the specification about what kind of Range
          is supported in ruby's custom type in YAML.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5731 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-02-16 14:41:49 +00:00
nahi 30e14294a7 * lib/csv.rb: add Cell#to_str and Cell#to_s for /.../ =~ aCell,
"#{aCell}" and so on.

        * test/csv/test_csv.rb: add tests.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5177 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-12-12 13:44:58 +00:00
nahi 11d2edffe6 * lib/csv.rb (IOReader, BasicWriter): call binmode when a given IO
respond_to?(:binmode).  record separator was wrong when you gave text mode IO
  to Reader.parse and Writer.generate.

* test/csv/test_csv.rb: add tests for above change.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4708 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-10-06 14:03:58 +00:00
nahi ffc136a024 * lib/csv.rb: add extra pamameter to specify row(record) separater character.
To parse Mac's CR separated CSV, do like this.
    CSV.open("mac.csv", "r", ?,,?\r) { |row| p row.to_a }
  The 3rd parameter in this example ?, is for column separater and the 4th ?\r
  is for row separater.  Row separater is nil by default.  Nil separater means
  "\r\n" or "\n".

* test/csv/test_csv.rb: add tests for above feature.

* test/csv/mac.csv: added.  Sample CR separated CSV file.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-09-15 10:07:42 +00:00
nahi 13e15cecf3 * lib/csv.rb: Import csv module.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3964 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2003-06-19 16:08:52 +00:00