Module: Duracloud::TSV
- Included in:
- AuditLog, BitIntegrityReport, Manifest
- Defined in:
- lib/duracloud/tsv.rb
Constant Summary collapse
- CHUNK_SIZE =
1024 * 16
Instance Method Summary collapse
- #csv ⇒ Object
- #load_tsv(io_or_str) ⇒ Object
- #load_tsv_file(path) ⇒ Object
- #rows ⇒ Object
- #table ⇒ Object
- #to_s ⇒ Object
- #tsv(&block) ⇒ Object
- #tsv_source ⇒ Object
- #tsv_source? ⇒ Boolean
Instance Method Details
#csv ⇒ Object
8 9 10 |
# File 'lib/duracloud/tsv.rb', line 8 def csv @csv ||= CSV.new(tsv, ) end |
#load_tsv(io_or_str) ⇒ Object
41 42 43 |
# File 'lib/duracloud/tsv.rb', line 41 def load_tsv(io_or_str) @tsv_source = io_or_str.is_a?(String) ? StringIO.new(io_or_str, "rb") : io_or_str end |
#load_tsv_file(path) ⇒ Object
53 54 55 |
# File 'lib/duracloud/tsv.rb', line 53 def load_tsv_file(path) load_tsv File.new(path, "rb") end |
#rows ⇒ Object
12 13 14 15 16 |
# File 'lib/duracloud/tsv.rb', line 12 def rows @rows ||= Enumerator.new do |e| table.each { |row| e << row.to_hash } end end |
#table ⇒ Object
18 19 20 21 22 23 |
# File 'lib/duracloud/tsv.rb', line 18 def table csv.rewind csv.read ensure csv.rewind end |
#to_s ⇒ Object
57 58 59 |
# File 'lib/duracloud/tsv.rb', line 57 def to_s tsv.to_s end |
#tsv(&block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/duracloud/tsv.rb', line 25 def tsv(&block) return unless tsv_source? begin tsv_source.rewind if block_given? while chunk = tsv_source.read(CHUNK_SIZE) yield chunk end else tsv_source.read end ensure tsv_source.rewind end end |
#tsv_source ⇒ Object
45 46 47 |
# File 'lib/duracloud/tsv.rb', line 45 def tsv_source @tsv_source end |
#tsv_source? ⇒ Boolean
49 50 51 |
# File 'lib/duracloud/tsv.rb', line 49 def tsv_source? !!@tsv_source end |