Class: GBTiles::GBM::Import::GBMFile
- Inherits:
-
Object
- Object
- GBTiles::GBM::Import::GBMFile
- Defined in:
- lib/gbtiles/gbm/import/gbm_file.rb
Constant Summary collapse
- OBJECT_MARKER =
"HPJMTL"
Instance Attribute Summary collapse
-
#map_set ⇒ Object
Returns the value of attribute map_set.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ GBMFile
constructor
A new instance of GBMFile.
Constructor Details
Instance Attribute Details
#map_set ⇒ Object
Returns the value of attribute map_set.
23 24 25 |
# File 'lib/gbtiles/gbm/import/gbm_file.rb', line 23 def map_set @map_set end |
#version ⇒ Object
Returns the value of attribute version.
22 23 24 |
# File 'lib/gbtiles/gbm/import/gbm_file.rb', line 22 def version @version end |
Class Method Details
.open(file) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/gbtiles/gbm/import/gbm_file.rb', line 29 def self.open file import = GBTiles::GBM::Import::GBMFile.new # Check to see if this is a valid file type if (file.read(3) != "GBO") then raise IOError, "Not a valid file (expected: GBO)" end # Version number import.version = file.read(1) if import.version != "1" then raise IOError, "Cannot import version #{import.version}" end # For each object while !file.eof? # Check the marker marker = GBTiles::DataType.string(file.read(6)) if !OBJECT_MARKER.eql? marker then raise "Malformed file, expected marker #{OBJECT_MARKER}, got #{marker}" end object_type = GBTiles::DataType.word(file.read(2)) object_id = GBTiles::DataType.word(file.read(2)) master_id = GBTiles::DataType.word(file.read(2)) object_crc = GBTiles::DataType.long(file.read(4)) object_len = GBTiles::DataType.long(file.read(4)) object_data = file.read(object_len) case GBTiles::GBM::Map::OBJECT_TYPE.key(object_type) when :producer object = GBTiles::GBM::Map::Objects::Producer.initFromBitString object_data when :map object = GBTiles::GBM::Map::Objects::Map.initFromBitString object_data when :map_tile_data object = GBTiles::GBM::Map::Objects::MapTileData.initFromBitString object_data when :map_settings object = GBTiles::GBM::Map::Objects::MapSettings.initFromBitString object_data when :map_export_settings object = GBTiles::GBM::Map::Objects::MapExportSettings.initFromBitString object_data else object = GBTiles::GBM::Map::Objects::Unknown.new object_type object.object_data = object_data end object.object_id = object_id object.master_id = master_id import.map_set.objects << object end import end |