Module: GBTiles::DataType
- Defined in:
- lib/gbtiles/data_type.rb
Class Method Summary collapse
-
.boolean(src) ⇒ Object
BOOLEAN 1 BYTE.
- .boolean!(src) ⇒ Object
-
.byte(src) ⇒ Object
BYTE 1 BYTE.
- .byte!(src) ⇒ Object
-
.long(src) ⇒ Object
LITTLE ENDIAN 32 BIT INTEGER 4 BYTES.
- .long!(src) ⇒ Object
- .string(src, length = nil) ⇒ Object
- .string!(src, length = nil) ⇒ Object
-
.word(src) ⇒ Object
WORD LITTLE ENDIAN 2 BYTES.
- .word!(src) ⇒ Object
Class Method Details
.boolean(src) ⇒ Object
BOOLEAN 1 BYTE
54 55 56 |
# File 'lib/gbtiles/data_type.rb', line 54 def self.boolean(src) src.slice!(0, 1).unpack("C")[0].eql? 1 end |
.boolean!(src) ⇒ Object
58 59 60 |
# File 'lib/gbtiles/data_type.rb', line 58 def self.boolean!(src) self.boolean(src.slice!(0, 1)) end |
.byte(src) ⇒ Object
BYTE 1 BYTE
44 45 46 |
# File 'lib/gbtiles/data_type.rb', line 44 def self.byte(src) src.slice(0, 1).unpack("C*")[0] end |
.byte!(src) ⇒ Object
48 49 50 |
# File 'lib/gbtiles/data_type.rb', line 48 def self.byte!(src) self.byte(src.slice!(0, 1)) end |
.long(src) ⇒ Object
LITTLE ENDIAN 32 BIT INTEGER 4 BYTES
65 66 67 |
# File 'lib/gbtiles/data_type.rb', line 65 def self.long(src) src.slice(0, 4).unpack("V*")[0] end |
.long!(src) ⇒ Object
69 70 71 |
# File 'lib/gbtiles/data_type.rb', line 69 def self.long!(src) self.long(src.slice!(0, 4)) end |
.string(src, length = nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/gbtiles/data_type.rb', line 3 def self.string(src, length = nil) if !length.nil? then string = src.slice(0, length) else string = src end if !string.nil? then string = string.split(/\0/).first end if !string.nil? string = string.unpack("A*")[0] end string end |
.string!(src, length = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/gbtiles/data_type.rb', line 21 def self.string!(src, length = nil) if !length.nil? then string = src.slice!(0, length) else string = src end self.string(string, length) end |
.word(src) ⇒ Object
WORD LITTLE ENDIAN 2 BYTES
34 35 36 |
# File 'lib/gbtiles/data_type.rb', line 34 def self.word(src) src.slice(0, 2).unpack("v*")[0] end |
.word!(src) ⇒ Object
38 39 40 |
# File 'lib/gbtiles/data_type.rb', line 38 def self.word!(src) self.word(src.slice!(0, 2)) end |