Class: EsriShapefile::ByteModel::Field
- Inherits:
-
Object
- Object
- EsriShapefile::ByteModel::Field
- Defined in:
- lib/esri_shapefile/byte_model/field.rb
Constant Summary collapse
- TYPES =
{ integer: { bytesize: 4, unpack: { big: 'l>', little: 'l<' } }, double: { bytesize: 8, unpack: { big: 'G', little: 'E' } }, point: { bytesize: 16, unpack: { big: 'G', little: 'E', multiplier: 2 } }, }
Instance Attribute Summary collapse
-
#byte_order ⇒ Object
readonly
Returns the value of attribute byte_order.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #bytesize(values = {}) ⇒ Object
-
#initialize(name, position:, type:, byte_order:, number: nil) ⇒ Field
constructor
A new instance of Field.
- #list? ⇒ Boolean
- #number_depends_on_field? ⇒ Boolean
- #unpack_format(values = {}) ⇒ Object
- #unused? ⇒ Boolean
Constructor Details
#initialize(name, position:, type:, byte_order:, number: nil) ⇒ Field
Returns a new instance of Field.
12 13 14 15 16 17 18 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 12 def initialize(name, position:, type:, byte_order:, number: nil) @name = name @position = position @type = type @number = number @byte_order = byte_order end |
Instance Attribute Details
#byte_order ⇒ Object (readonly)
Returns the value of attribute byte_order.
4 5 6 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 4 def byte_order @byte_order end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 4 def name @name end |
#number ⇒ Object (readonly)
Returns the value of attribute number.
4 5 6 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 4 def number @number end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
4 5 6 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 4 def position @position end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 4 def type @type end |
Instance Method Details
#bytesize(values = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 36 def bytesize(values = {}) size = TYPES[@type][:bytesize] if number_depends_on_field? multiplier = TYPES[@type][:unpack][:multiplier] || 1 number_of_consecutive_values = number_depends_on_field? ? values[number] : number number_of_consecutive_values * multiplier * size else size end end |
#list? ⇒ Boolean
20 21 22 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 20 def list? !@number.nil? end |
#number_depends_on_field? ⇒ Boolean
28 29 30 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 28 def number_depends_on_field? @number.is_a?(Symbol) end |
#unpack_format(values = {}) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 48 def unpack_format(values = {}) number_of_consecutive_values = number_depends_on_field? ? values[number] : number multiplier = TYPES[@type][:unpack][:multiplier] || 1 unpack_format = TYPES[@type][:unpack][@byte_order] "#{unpack_format}#{number_of_consecutive_values * multiplier}" end |
#unused? ⇒ Boolean
32 33 34 |
# File 'lib/esri_shapefile/byte_model/field.rb', line 32 def unused? name == :unused end |