Class: Keep::Manifest
- Inherits:
-
Object
- Object
- Keep::Manifest
- Defined in:
- lib/arvados/keep.rb
Instance Method Summary collapse
- #each_file ⇒ Object
- #each_stream ⇒ Object
-
#initialize(manifest_text) ⇒ Manifest
constructor
Class to parse a manifest text and provide common views of that data.
- #unescape(s) ⇒ Object
Constructor Details
#initialize(manifest_text) ⇒ Manifest
Class to parse a manifest text and provide common views of that data.
95 96 97 |
# File 'lib/arvados/keep.rb', line 95 def initialize(manifest_text) @text = manifest_text end |
Instance Method Details
#each_file ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/arvados/keep.rb', line 113 def each_file return to_enum(__method__) unless block_given? each_stream do |streamname, blocklist, filelist| filelist.each do |filespec| start_pos, filesize, filename = filespec.split(':', 3) yield [streamname, filename, filesize.to_i] end end end |
#each_stream ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/arvados/keep.rb', line 99 def each_stream return to_enum(__method__) unless block_given? @text.each_line do |line| tokens = line.split stream_name = unescape(tokens.shift) blocks = [] while loc = Locator.parse(tokens.first) blocks << loc tokens.shift end yield [stream_name, blocks, tokens.map { |s| unescape(s) }] end end |
#unescape(s) ⇒ Object
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/arvados/keep.rb', line 123 def unescape(s) s.gsub(/\\(\\|[0-7]{3})/) do |_| case $1 when '\\' '\\' else $1.to_i(8).chr end end end |