Class: Codnar::Reader
- Inherits:
-
Object
- Object
- Codnar::Reader
- Defined in:
- lib/codnar/reader.rb
Overview
Read chunks from disk files.
Direct Known Subclasses
Instance Method Summary collapse
-
#[](name) ⇒ Object
Fetch a chunk by its name.
-
#collect_unused_chunk_errors ⇒ Object
Collect errors for unused chunks.
-
#initialize(errors, paths) ⇒ Reader
constructor
Load all chunks from the specified disk files to memory for later access by name.
Constructor Details
#initialize(errors, paths) ⇒ Reader
Load all chunks from the specified disk files to memory for later access by name.
8 9 10 11 12 13 14 15 |
# File 'lib/codnar/reader.rb', line 8 def initialize(errors, paths) @errors = errors @chunks = {} @used = {} paths.each do |path| read_path_chunks(path) end end |
Instance Method Details
#[](name) ⇒ Object
Fetch a chunk by its name.
18 19 20 21 22 23 24 25 |
# File 'lib/codnar/reader.rb', line 18 def [](name) id = name.to_id @used[id] = true return @chunks[id] ||= ( @errors << "Missing chunk: #{name}" Reader.fake_chunk(name) ) end |
#collect_unused_chunk_errors ⇒ Object
Collect errors for unused chunks.
28 29 30 31 32 |
# File 'lib/codnar/reader.rb', line 28 def collect_unused_chunk_errors @chunks.each do |id, chunk| @errors.push("#{$0}: Unused chunk: #{chunk.name} #{Reader.locations_message(chunk)}") unless @used[id] end end |