Class: FiasReader::Cache::AddressPart
- Inherits:
-
Object
- Object
- FiasReader::Cache::AddressPart
- Includes:
- DataMapper::Resource
- Defined in:
- lib/fias_reader/cache/address_part.rb,
lib/fias_reader/cache/address_part/level_adapter.rb
Defined Under Namespace
Classes: LevelAdapter
Constant Summary collapse
- ZERO_STR =
'0'.freeze
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.index(reader) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/fias_reader/cache/address_part.rb', line 50 def self.index(reader) attrs = properties.map(&:name) FiasReader::Table::AddressPart.new(reader).query.all do |row| next if row[:LIVESTATUS] == ZERO_STR begin params = FiasReader::Cache::Guid.new(row[:AOGUID]).to_attr(:id) params.merge! FiasReader::Cache::Guid.new(row[:PARENTGUID]).to_attr(:parent) params[:SHORTNAME] = row[:SHORTNAME] params[:OFFNAME] = row[:OFFNAME] params[:AOLEVEL] = row[:AOLEVEL] create params rescue DataObjects::IntegrityError => e end end end |
.index_levels ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/fias_reader/cache/address_part.rb', line 66 def self.index_levels puts "Части 4..." index_levels_batch '4' puts "Части 6..." index_levels_batch '6' puts "Части 7..." index_levels_batch '7' end |
.index_levels_batch(level) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fias_reader/cache/address_part.rb', line 75 def self.index_levels_batch(level) start = -1 i = 0 while start != i start = i all(offset: i, limit: 1000, AOLEVEL: level).each do |item| i += 1 puts Time.new if (i % 10_000).zero? item.parent_string end end end |
Instance Method Details
#levels ⇒ Object
89 90 91 |
# File 'lib/fias_reader/cache/address_part.rb', line 89 def levels @levels ||= FiasReader::Cache::AddressPart::LevelAdapter.new(self) end |
#parent_string ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fias_reader/cache/address_part.rb', line 93 def parent_string return levels if levels_filled if parent0.nil? levels.reset_own else # some bug with parent DataObjects::SyntaxError, so using first parent_item = FiasReader::Cache::AddressPart.first(id0: parent0, id1: parent1, id2: parent2, id3: parent3) if parent_item levels.copy(parent_item.parent_string) else levels.reset_own end save end levels end |