Changeset 108
- Timestamp:
- 09/02/06 11:25:47 (2 years ago)
- Files:
-
- trunk/lib/csv.rb (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/csv.rb
r107 r108 42 42 # 43 43 # ARGS 44 # filename: filename to parse. 45 # col_sep: Column separator. ?, by default. If you want to separate 46 # fields with semicolon, give ?; here. 47 # row_sep: Row separator. nil by default. nil means "\r\n or \n". If you 48 # want to separate records with \r, give ?\r here. 44 # path: filename to parse/generate. 45 # mode: 'r', 'rb', 'w', or 'wb'. r for read, w for write, b for binary. 46 # fs: field separator. ?, by default. If you want to separate fields with 47 # semicolon, give ?; here. 48 # rs: record separator. nil by default. nil means "\r\n or \n". If you 49 # want to separate records with \r, give ?\r here. 49 50 # 50 51 # RETURNS … … 65 66 # writer << ['r1c1', 'r1c2'] << ['r2c1', 'r2c2'] << [nil, nil] 66 67 # writer.close 67 #68 # ARGS69 # filename: filename to generate.70 # col_sep: Column separator. ?, by default. If you want to separate71 # fields with semicolon, give ?; here.72 # row_sep: Row separator. nil by default. nil means "\r\n or \n". If you73 # want to separate records with \r, give ?\r here.74 68 # 75 69 # RETURNS … … 194 188 # ARGS 195 189 # src: a CSV data to be parsed. Must respond '[](idx)'. 196 # src[](idx) must return a char. (Not a string such as 'a', but 97).197 # src[](idx_out_of_bounds) must return nil. A String satisfies this198 # requirement.190 # src[](idx) must return a char. (Not a string such as 'a', but 97). 191 # src[](idx_out_of_bounds) must return nil. A String satisfies this 192 # requirement. 199 193 # idx: index of parsing location of 'src'. 0 origin. 200 194 # out_dev: buffer for parsed cells. Must respond '<<(aString)'. 201 # col_sep: Column separator. ?, by default. If you want to separate202 # fields withsemicolon, give ?; here.203 # r ow_sep: Rowseparator. nil by default. nil means "\r\n or \n". If you204 # want to separate records with \r, give ?\r here.195 # fs: field separator. ?, by default. If you want to separate fields with 196 # semicolon, give ?; here. 197 # rs: record separator. nil by default. nil means "\r\n or \n". If you 198 # want to separate records with \r, give ?\r here. 205 199 # 206 200 # RETURNS … … 255 249 # ARGS 256 250 # src: an Array of String to be converted to CSV string. Must respond to 257 # 'size' and '[](idx)'. src[idx] must return String.251 # 'size' and '[](idx)'. src[idx] must return String. 258 252 # cells: num of cells in a line. 259 253 # out_dev: buffer for generated CSV string. Must respond to '<<(string)'. 260 # col_sep: Column separator. ?, by default. If you want to separate261 # fields withsemicolon, give ?; here.262 # r ow_sep: Rowseparator. nil by default. nil means "\r\n or \n". If you263 # want to separate records with \r, give ?\r here.254 # fs: field separator. ?, by default. If you want to separate fields with 255 # semicolon, give ?; here. 256 # rs: record separator. nil by default. nil means "\r\n or \n". If you 257 # want to separate records with \r, give ?\r here. 264 258 # 265 259 # RETURNS … … 508 502 end 509 503 504 510 505 class Table 511 506 include KeywordArgument … … 601 596 # CSV::Reader.parse(File.open('bigdata', 'rb')) do |row| 602 597 # p row 603 # break if !row[0].is_null && row[0].data== 'stop'598 # break if row[0] == 'stop' 604 599 # end 605 600 # … … 608 603 609 604 # Parse CSV data and get lines. Given block is called for each parsed row. 610 # Block value is always nil. Rows are not cached for performance reason.605 # Block value is always nil. records are not cached for performance reason. 611 606 def Reader.parse(str_or_readable, fs = ',', rs = nil, &block) 612 607 reader = Reader.create(str_or_readable, fs, rs) … … 663 658 664 659 def get_row(row) 665 raise NotImplementedError.new('Method get_row must be defined in a derived class.') 660 raise NotImplementedError.new( 661 'Method get_row must be defined in a derived class.') 666 662 end 667 663 … … 703 699 @dev = CSV::IOBuf.new(@io) 704 700 @idx = 0 705 if @dev[0 ] == 0xef and @dev[1] == 0xbb and @dev[2] == 0xbf701 if @dev[0, 3] == "\xef\xbb\xbf" 706 702 @idx += 3 707 703 end