Class: FiasReader::Scope
- Inherits:
-
Object
- Object
- FiasReader::Scope
- Defined in:
- lib/fias_reader/scope.rb
Overview
Инерфейс для работы XML с базой ФИАС
Instance Attribute Summary collapse
-
#logics ⇒ Object
readonly
Returns the value of attribute logics.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #all ⇒ Object
- #default_parser ⇒ Object
- #first ⇒ Object
-
#initialize(table) ⇒ Scope
constructor
A new instance of Scope.
- #parse!(parser = default_parser) ⇒ Object
- #select(*args) ⇒ Object
Constructor Details
#initialize(table) ⇒ Scope
Returns a new instance of Scope.
6 7 8 9 10 |
# File 'lib/fias_reader/scope.rb', line 6 def initialize(table) @table = table @options = {} @logics = @table.class::LOGICS.dup end |
Instance Attribute Details
#logics ⇒ Object (readonly)
Returns the value of attribute logics.
4 5 6 |
# File 'lib/fias_reader/scope.rb', line 4 def logics @logics end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/fias_reader/scope.rb', line 4 def @options end |
Instance Method Details
#all ⇒ Object
12 13 14 15 |
# File 'lib/fias_reader/scope.rb', line 12 def all @options[:rows] = -> (row) { yield row } parse! end |
#default_parser ⇒ Object
40 41 42 |
# File 'lib/fias_reader/scope.rb', line 40 def default_parser FiasReader::Parser.new(logics, @options) end |
#first ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/fias_reader/scope.rb', line 17 def first result = nil catch :fias_parse_stop do @options[:rows] = -> (row) do result = row throw :fias_parse_stop end parse! end result end |
#parse!(parser = default_parser) ⇒ Object
36 37 38 |
# File 'lib/fias_reader/scope.rb', line 36 def parse!(parser = default_parser) Ox.sax_parse parser, @table.file, symbolize: true end |
#select(*args) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/fias_reader/scope.rb', line 29 def select(*args) index = @logics.index(FiasReader::ParseLogic::Attributes) @logics[index] = FiasReader::ParseLogic::AttributesSelect if index @options[:select] = args self end |