Class: Dubliner
- Inherits:
-
Object
show all
- Includes:
- Helper
- Defined in:
- lib/dubliner.rb
Constant Summary
collapse
- VERSION =
'0.1.0'
Instance Method Summary
collapse
Methods included from Helper
#distanceCalculator, #earthRadius, #fileRead, #jsonParse
Constructor Details
#initialize(latitude, longitude) ⇒ Dubliner
Returns a new instance of Dubliner.
5
6
7
8
|
# File 'lib/dubliner.rb', line 5
def initialize(latitude, longitude)
self.latitude = latitude
self.longitude = longitude
end
|
Instance Method Details
#getInvitees(filename) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/dubliner.rb', line 20
def getInvitees(filename)
file = fileRead(filename)
customers = jsonParse(file)
invitees = []
longestName = 0
customers.each do |c|
distance = distanceCalculator(c.latitude, c.longitude, @latitude, @longitude)
if distance < 100.0
c.distance = distance
invitees.push(c)
longestName = c.name.length unless longestName >=c.name.length
end
end
invitees.sort_by! {|i| i.user_id}
printInvitees(invitees, longestName)
end
|
#latitude=(l) ⇒ Object
10
11
12
13
|
# File 'lib/dubliner.rb', line 10
def latitude=(l)
raise ArgumentError.new("latitude #{l} is invalid") unless l
@latitude = (l.to_f * Math::PI) / 180
end
|
#longitude=(l) ⇒ Object
15
16
17
18
|
# File 'lib/dubliner.rb', line 15
def longitude=(l)
raise ArgumentError.new("longitude #{l} is invalid") unless l
@longitude = (l.to_f * Math::PI) / 180
end
|
#printInvitees(invitees, width) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/dubliner.rb', line 37
def printInvitees(invitees, width)
printf "count %-#{width}s %s %s", 'invitees', 'user_id', 'distance(km)'
puts ''
puts '-------------------------------------------------------------------------'
counter = 1
invitees.each do |i|
printf "%3d %-#{width}s %3d %-3.2f\n", counter, i.name, i.user_id, i.distance
counter += 1
end
puts '-------------------------------------------------------------------------'
end
|