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
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#parsed ⇒ Object
Returns the value of attribute parsed.
-
#relations ⇒ Object
Returns the value of attribute relations.
-
#ways ⇒ Object
Returns the value of attribute ways.
Instance Method Summary collapse
- #flush_all ⇒ Object
-
#initialize(database, collections, qlimit, parser, host, port) ⇒ 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, host, port) ⇒ Callbacks
Returns a new instance of Callbacks.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/callbacks.rb', line 37 def initialize(database, collections, qlimit, parser, host, port) @nodes = DB::Mongohandler.new(database, collections[NODE], qlimit, host, port) @nodes.connect() @ways = DB::Mongohandler.new(database, collections[WAY], qlimit, host, port) @ways.use_connection(@nodes.connection) @relations = DB::Mongohandler.new(database, collections[RELATION], qlimit, host, port) @relations.use_connection(@nodes.connection) parser.add_observer(self) @parsed = false end |
Instance Attribute Details
#nodes ⇒ Object
Returns the value of attribute nodes.
35 36 37 |
# File 'lib/callbacks.rb', line 35 def nodes @nodes end |
#parsed ⇒ Object
Returns the value of attribute parsed.
34 35 36 |
# File 'lib/callbacks.rb', line 34 def parsed @parsed end |
#relations ⇒ Object
Returns the value of attribute relations.
35 36 37 |
# File 'lib/callbacks.rb', line 35 def relations @relations end |
#ways ⇒ Object
Returns the value of attribute ways.
35 36 37 |
# File 'lib/callbacks.rb', line 35 def ways @ways end |
Instance Method Details
#flush_all ⇒ Object
66 67 68 69 70 71 |
# File 'lib/callbacks.rb', line 66 def flush_all @nodes.flush() @ways.flush() @relations.flush() @parsed = true end |
#node(reader) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/callbacks.rb', line 73 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
89 90 91 92 93 94 95 |
# File 'lib/callbacks.rb', line 89 def relation(reader) attributes = {MID => reader.attribute(ID)} unless reader.empty_element? extract_children(reader, attributes) end @relations.add(attributes) end |