Class: HMap::MapFileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/hmap/hmap/hmap_reader.rb

Overview

hmap file reader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ MapFileReader

Returns a new instance of MapFileReader.

Raises:

  • (ArgumentError)


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

#bucktesHash<HMap::HMapBucket => HMap::BucketStr> (readonly)

Note:

bucktes are provided in order of ascending offset.

Returns an array of the file’s bucktes.

Returns:



21
22
23
# File 'lib/hmap/hmap/hmap_reader.rb', line 21

def bucktes
  @bucktes
end

#filenameString? (readonly)

Returns the filename loaded from, or nil if loaded from a binary string.

Returns:

  • (String, nil)

    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

#headerHMap::HMapHeader (readonly)

Returns:



17
18
19
# File 'lib/hmap/hmap/hmap_reader.rb', line 17

def header
  @header
end

#swappedObject (readonly)

Returns true/false the swapped of the mapfile.

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_fieldsvoid

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