Class: GeoRuby::Shp4r::Dbf::Reader
- Inherits:
-
Object
- Object
- GeoRuby::Shp4r::Dbf::Reader
- Defined in:
- lib/geo_ruby/shp4r/dbf.rb
Instance Attribute Summary collapse
-
#field_count ⇒ Object
readonly
Returns the value of attribute field_count.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#header_length ⇒ Object
readonly
Returns the value of attribute header_length.
-
#last_updated ⇒ Object
readonly
Returns the value of attribute last_updated.
-
#record_count ⇒ Object
readonly
Returns the value of attribute record_count.
-
#record_length ⇒ Object
readonly
Returns the value of attribute record_length.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
- #field(field_name) ⇒ Object
-
#initialize(file) ⇒ Reader
constructor
A new instance of Reader.
-
#record(index) ⇒ Object
(also: #row)
Jump to record.
-
#records ⇒ Object
(also: #rows)
An array of all the records contained in the database file.
- #reload! ⇒ Object
- #version_description ⇒ Object
Constructor Details
#initialize(file) ⇒ Reader
Returns a new instance of Reader.
37 38 39 40 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 37 def initialize(file) @data_file = File.open(file, 'rb') reload! end |
Instance Attribute Details
#field_count ⇒ Object (readonly)
Returns the value of attribute field_count.
29 30 31 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 29 def field_count @field_count end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
30 31 32 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 30 def fields @fields end |
#header_length ⇒ Object (readonly)
Returns the value of attribute header_length.
34 35 36 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 34 def header_length @header_length end |
#last_updated ⇒ Object (readonly)
Returns the value of attribute last_updated.
33 34 35 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 33 def last_updated @last_updated end |
#record_count ⇒ Object (readonly)
Returns the value of attribute record_count.
31 32 33 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 31 def record_count @record_count end |
#record_length ⇒ Object (readonly)
Returns the value of attribute record_length.
35 36 37 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 35 def record_length @record_length end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
32 33 34 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 32 def version @version end |
Class Method Details
.open(file) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 42 def self.open(file) reader = Reader.new(file) if block_given? yield reader reader.close else reader end end |
Instance Method Details
#close ⇒ Object
52 53 54 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 52 def close @data_file.close end |
#field(field_name) ⇒ Object
61 62 63 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 61 def field(field_name) @fields.detect {|f| f.name == field_name.to_s} end |
#record(index) ⇒ Object Also known as: row
Jump to record
80 81 82 83 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 80 def record(index) seek_to_record(index) active_record? ? build_record : nil end |
#records ⇒ Object Also known as: rows
An array of all the records contained in the database file
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 66 def records seek_to_record(0) @records ||= Array.new(@record_count) do |i| if active_record? build_record else seek_to_record(i + 1) nil end end end |
#reload! ⇒ Object
56 57 58 59 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 56 def reload! get_header_info get_field_descriptors end |
#version_description ⇒ Object
87 88 89 |
# File 'lib/geo_ruby/shp4r/dbf.rb', line 87 def version_description VERSION_DESCRIPTIONS[version] end |