Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions lib/geo_ruby/shp4r/dbf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def [](v)
end
end

class Field < Column::Base
class Field < ColumnType::Base
def initialize(name, type, length, decimal = 0, version = 1, enc = nil)
super(name, type, length, decimal, version, enc)
end
Expand All @@ -33,8 +33,10 @@ def header_length
@columns_count
end

def self.open(f)
new(f)
# Open DBF with specified encoding (it can also be nil and DBF reader
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/Tab: Tab detected.

# will use what it finds in header).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/Tab: Tab detected.

def self.open(f, memo = nil, encoding)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/Tab: Tab detected.
Layout/IndentationConsistency: Inconsistent indentation detected.
Naming/UncommunicativeMethodParamName: Method parameter must be at least 3 characters long.

new(f, memo, encoding)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/IndentationWidth: Use 2 (not 8) spaces for indentation.

end

def close
Expand Down
10 changes: 6 additions & 4 deletions lib/geo_ruby/shp4r/shp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ShpFile

# Opens a SHP file. Both "abc.shp" and "abc" are accepted.
# The files "abc.shp", "abc.shx" and "abc.dbf" must be present
def initialize(file)
def initialize(file, dbf_encoding)
# strip the shp out of the file if present
@file_root = file.gsub(/.shp$/i, '')
# check existence of shp, dbf and shx files
Expand All @@ -41,7 +41,7 @@ def initialize(file)
fail MalformedShpException.new("Missing one of shp, dbf or shx for: #{@file}")
end

@dbf = Dbf::Reader.open(@file_root + '.dbf')
@dbf = Dbf::Reader.open(@file_root + '.dbf', nil, dbf_encoding)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@shx = File.open(@file_root + '.shx', 'rb')
@shp = File.open(@file_root + '.shp', 'rb')
read_index
Expand All @@ -56,8 +56,10 @@ def reload!
# opens a SHP "file". If a block is given, the ShpFile object
# is yielded to it and is closed upon return.
# Else a call to <tt>open</tt> is equivalent to <tt>ShpFile.new(...)</tt>.
def self.open(file)
shpfile = ShpFile.new(file)
# You can specify encoding of the table, by default it is not set, maybe
# it should be UTF-8?
def self.open(file, dbf_encoding = nil)
shpfile = ShpFile.new(file, dbf_encoding)
if block_given?
yield shpfile
shpfile.close
Expand Down