Class: Gdbmish::Read::Ascii
- Inherits:
-
Object
- Object
- Gdbmish::Read::Ascii
- Defined in:
- lib/gdbmish/read.rb
Overview
Main abstraction to read an GDBM Ascii dump file (aka "standard format")
Instance Method Summary collapse
-
#data {|key, value| ... } ⇒ AsciiDataIterator
Returns an Enumerator over key/value pairs.
-
#initialize(io, load_meta: true, encoding: Encoding::UTF_8) ⇒ Ascii
constructor
Create a new Ascii reader.
-
#meta ⇒ AsciiMetaData?
Parses for meta data, depending on the load_meta value in #initialize.
Constructor Details
#initialize(io, load_meta: true, encoding: Encoding::UTF_8) ⇒ Ascii
Create a new Ascii reader.
load_meta can be:
true
(default) load meta data, but skipcount
for preformance reasons.false
skip loading meta data.:count
load meta data, includingcount
.
39 40 41 42 43 |
# File 'lib/gdbmish/read.rb', line 39 def initialize(io, load_meta: true, encoding: Encoding::UTF_8) @io = io @load_meta = @encoding = encoding end |
Instance Method Details
#data {|key, value| ... } ⇒ AsciiDataIterator
Note:
This will consume the IO, so you can only iterate once. After that, you need to rewind the IO.
Returns an Enumerator over key/value pairs.
Given a block, it will yield each key/value pair, which is a shortcut for #data.each
.
Depending on the size of the dataset, you might want to read everything into an Array or Hash:
Ascii.new(io1).data.to_a # => [["some_key", "Some Value"], ["otherKey", "Other\nValue"]]
Ascii.new(io2).data.to_h # => {"some_key" => "Some Value", "otherKey" => "Other\nValue"}
60 61 62 63 64 |
# File 'lib/gdbmish/read.rb', line 60 def data(&block) @data_iterator ||= AsciiDataIterator.new(@io, encoding: @encoding) block ? @data_iterator.each(&block) : @data_iterator end |
#meta ⇒ AsciiMetaData?
Parses for meta data, depending on the load_meta value in #initialize
68 69 70 |
# File 'lib/gdbmish/read.rb', line 68 def end |