Class: App

Inherits:
Object
  • Object
show all
Defined in:
lib/osm2mongo.rb

Constant Summary collapse

VERSION =
'0.0.2'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments, stdin) ⇒ App


52
53
54
55
56
57
58
59
60
# File 'lib/osm2mongo.rb', line 52

def initialize(arguments, stdin)
  @arguments = arguments
  @stdin = stdin
  
  # Set defaults
  @options = OpenStruct.new
  # TO DO - add additional defaults
  @todos = Hash.new
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


50
51
52
# File 'lib/osm2mongo.rb', line 50

def options
  @options
end

Instance Method Details

#runObject

Parse options, check arguments, then process the command


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/osm2mongo.rb', line 63

def run
      
  if parsed_options? && arguments_valid? 
    
    output_options if @options.verbose # [Optional]
          
    process_arguments
    
    collections = {"node" => "nodes", "way" => "ways", "relation" => "rels"}
    common = Osm2Mongo::Common.new()
    callback = Osm2Mongo::Callbacks.new(@todos['db'], collections, Integer(@todos['limit']), common, @todos['host'], @todos['port'])
    file_path = ''
    beginning_time = Time.now
    
    if @todos.has_key?("feature") or @todos.has_key?("subfeature")
        filter = DB::Classifier.new(@todos['db'], @todos['limit'], @todos['host'], @todos['port'])
        result = 0

        if @todos.has_key?("subfeature")
            result = filter.classify_subtype(@todos['feature'], @todos['subfeature'])
        else
            result = filter.classify_all(@todos['feature'])
        end
        end_time = Time.now
        puts "\n Processed Objects :(#{result}) >>> Elapsed: #{(end_time - beginning_time)}"
        return 0
    end
    
    unless @todos.has_key?("file")
        status = common.download(@todos['url'], "/tmp/")
        status = common.decompress(status['path'])
        file_path = status['path']
    else
        file_path = @todos['file']
    end
    common.parse(file_path)
    end_time = Time.now
    puts "\nNodes:(#{callback.nodes.collection.count})  Ways:(#{callback.ways.collection.count})  Rels:(#{callback.relations.collection.count}) >>> Elapsed: #{(end_time - beginning_time)}"
    
  else
    output_usage
  end
    
end