-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.rb
44 lines (38 loc) · 1.03 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'mongo'
class DB
def initialize()
@client = Mongo::Client.new(["#{ENV['MONGO_HOST']}:#{ENV['MONGO_PORT']}"], :database => 'cars')
@collection = @client[:cars]
end
def find_by_manufacture(manufacture)
@collection.find({manufacture: manufacture}).to_a
end
def find_later_then(year)
@collection.find({year: {'$gte': year.to_i}}).to_a
end
def find_by_id(id)
@collection.find({_id: BSON::ObjectId(id)}).first.dig('car_options')
end
end
def handle_input(input)
db = DB.new()
case input
in ['manufacture', manufacture]
db.find_by_manufacture(manufacture)
in ['later_then', year]
db.find_later_then(year)
in ['options', id]
db.find_by_id(id)
in ['help']
"""
Flags for app.rb:
manufacture <manufacture> -- finds all cars by manufacture
later_then <year> -- finds all cars which were produced after year
options <id> -- puts options of car with id
help -- puts help
"""
else
'Wrong command. Print "ruby app.rb help" for help.'
end
end
puts handle_input(ARGV)