Class: Osm2Mongo::Callbacks
- Inherits:
-
Object
- Object
- Osm2Mongo::Callbacks
- Defined in:
- lib/callbacks.rb
Overview
Container: Responsible for inserting data.
Purpose:
Ability to bulk insert data by limit set at intantiation.
Depends:
-
Container: Handler for MongoDB.
Constant Summary collapse
- NODE =
"node"
- WAY =
"way"
- RELATION =
"relation"
- TAG =
"tag"
- TEXT =
"#text"
- NODEREF =
"nd"
- MEMBER =
"member"
- NDS =
"nodes"
- TGS =
"tags"
- MBS =
"members"
- DONE =
"done"
- KEY =
"k"
- VALUE =
"v"
- ID =
"id"
- MID =
"_id"
- LON =
"lon"
- LAT =
"lat"
- REF =
"ref"
Instance Attribute Summary collapse
-
#parsed ⇒ Object
Returns the value of attribute parsed.
Instance Method Summary collapse
- #flush_all ⇒ Object
-
#initialize(database, collections, qlimit, parser) ⇒ Callbacks
constructor
A new instance of Callbacks.
- #node(reader) ⇒ Object
- #relation(reader) ⇒ Object
- #update(reader) ⇒ Object
- #way(reader) ⇒ Object
Constructor Details
#initialize(database, collections, qlimit, parser) ⇒ Callbacks
Returns a new instance of Callbacks.
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/callbacks.rb', line 36 def initialize(database, collections, qlimit, parser) @nodes = DB::Mongohandler.new(database, collections[NODE], qlimit) @nodes.connect() @ways = DB::Mongohandler.new(database, collections[WAY], qlimit) @ways.use_connection(@nodes.connection) @relations = DB::Mongohandler.new(database, collections[RELATION], qlimit) @relations.use_connection(@nodes.connection) parser.add_observer(self) @parsed = false end |
Instance Attribute Details
#parsed ⇒ Object
Returns the value of attribute parsed.
34 35 36 |
# File 'lib/callbacks.rb', line 34 def parsed @parsed end |
Instance Method Details
#flush_all ⇒ Object
65 66 67 68 69 70 |
# File 'lib/callbacks.rb', line 65 def flush_all @nodes.flush() @ways.flush() @relations.flush() @parsed = true end |
#node(reader) ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/callbacks.rb', line 72 def node(reader) attributes = {MID => reader.attribute(ID), LON => reader.attribute(LON), LAT => reader.attribute(LAT)} unless reader.empty_element? extract_children(reader, attributes) end @nodes.add(attributes) end |
#relation(reader) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/callbacks.rb', line 88 def relation(reader) attributes = {MID => reader.attribute(ID)} unless reader.empty_element? extract_children(reader, attributes) end @relations.add(attributes) end |