class Fias::Import::Dbf
Constants
- DEFAULT_ENCODING
- HOUSE_TABLES
- NORDOC_TABLES
- TABLES
Attributes
files[R]
Public Class Methods
new(path, encoding = DEFAULT_ENCODING)
click to toggle source
# File lib/fias/import/dbf.rb, line 4 def initialize(path, encoding = DEFAULT_ENCODING) @path = path @files = {} unless Dir.exist?(@path) fail ArgumentError, "FIAS database path #{@path} does not exists" end open_files(encoding) end
Private Class Methods
n_tables(title)
click to toggle source
# File lib/fias/import/dbf.rb, line 44 def self.n_tables(title) tables = (1..99).map do |n| [ format('%s%0.2d', title, n).to_sym, format('%s%0.2d.DBF', title.upcase, n) ] end tables.flatten! Hash[*tables] end
Public Instance Methods
only(*names)
click to toggle source
# File lib/fias/import/dbf.rb, line 15 def only(*names) return @files if names.empty? names = names.map do |name| name = name.to_sym name == :houses ? HOUSE_TABLES.keys : name name == :nordocs ? NORDOC_TABLES.keys : name end names.flatten! @files.slice(*names) end
Private Instance Methods
open_files(encoding)
click to toggle source
# File lib/fias/import/dbf.rb, line 33 def open_files(encoding) TABLES.each do |accessor, dbf_filename| filename = File.join(@path, dbf_filename) next unless File.exist?(filename) dbf = DBF::Table.new(filename, nil, encoding) @files[accessor] = dbf if dbf end end