Class: HMap::MapFileReader
- Inherits:
-
Object
- Object
- HMap::MapFileReader
- Defined in:
- lib/hmap/hmap/hmap_reader.rb
Overview
hmap file reader
Instance Attribute Summary collapse
-
#bucktes ⇒ Hash<HMap::HMapBucket => HMap::BucketStr>
readonly
An array of the file’s bucktes.
-
#filename ⇒ String?
readonly
The filename loaded from, or nil if loaded from a binary string.
- #header ⇒ HMap::HMapHeader readonly
-
#swapped ⇒ Object
readonly
True/false the swapped of the mapfile.
Instance Method Summary collapse
-
#initialize(path) ⇒ MapFileReader
constructor
A new instance of MapFileReader.
-
#populate_fields ⇒ void
Populate the instance’s fields with the raw HMap data.
Constructor Details
#initialize(path) ⇒ MapFileReader
Returns a new instance of MapFileReader.
23 24 25 26 27 28 29 30 |
# File 'lib/hmap/hmap/hmap_reader.rb', line 23 def initialize(path) raise ArgumentError, "#{path}: no such file" unless File.file?(path) @filename = path @raw_data = File.open(@filename, 'rb', &:read) populate_fields puts description end |
Instance Attribute Details
#bucktes ⇒ Hash<HMap::HMapBucket => HMap::BucketStr> (readonly)
Note:
bucktes are provided in order of ascending offset.
Returns an array of the file’s bucktes.
21 22 23 |
# File 'lib/hmap/hmap/hmap_reader.rb', line 21 def bucktes @bucktes end |
#filename ⇒ String? (readonly)
Returns the filename loaded from, or nil if loaded from a binary string.
9 10 11 |
# File 'lib/hmap/hmap/hmap_reader.rb', line 9 def filename @filename end |
#header ⇒ HMap::HMapHeader (readonly)
17 18 19 |
# File 'lib/hmap/hmap/hmap_reader.rb', line 17 def header @header end |
#swapped ⇒ Object (readonly)
Returns true/false the swapped of the mapfile.
14 15 16 |
# File 'lib/hmap/hmap/hmap_reader.rb', line 14 def swapped @swapped end |
Instance Method Details
#populate_fields ⇒ void
Note:
This method is public, but should (almost) never need to be called.
This method returns an undefined value.
Populate the instance’s fields with the raw HMap data.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hmap/hmap/hmap_reader.rb', line 35 def populate_fields @header = populate_hmap_header string_t = @raw_data[header.strings_offset..] @bucktes = populate_buckets do |bucket| bucket_s = bucket.to_a.map do |key| string_t[key..].match(/[^\0]+/)[0] end BucketStr.new(*bucket_s) end end |