Class: HMap::MapFileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/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)


39
40
41
42
43
44
45
46
# File 'lib/hmap/hmap_reader.rb', line 39

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::HMapBucketStr> (readonly)

Note:

bucktes are provided in order of ascending offset.

Returns an array of the file’s bucktes.

Returns:



37
38
39
# File 'lib/hmap/hmap_reader.rb', line 37

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



25
26
27
# File 'lib/hmap/hmap_reader.rb', line 25

def filename
  @filename
end

#headerHMap::HMapHeader (readonly)

Returns:



33
34
35
# File 'lib/hmap/hmap_reader.rb', line 33

def header
  @header
end

#swappedObject (readonly)

Returns true/false the swapped of the mapfile.

Returns:

  • true/false the swapped of the mapfile



30
31
32
# File 'lib/hmap/hmap_reader.rb', line 30

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.



51
52
53
54
55
56
57
58
59
60
# File 'lib/hmap/hmap_reader.rb', line 51

def populate_fields
  @header = populate_hmap_header
  string_t = @raw_data[header.strings_offset..-1]
  @bucktes = populate_buckets do |bucket|
    bucket_s = bucket.to_a.map do |key|
      string_t[key..-1].match(/[^\0]+/)[0]
    end
    HMapBucketStr.new(*bucket_s)
  end
end