Class: BB::BaseBoundingBox
- Inherits:
-
Object
- Object
- BB::BaseBoundingBox
show all
- Defined in:
- lib/bounding_boxes/base_bounding_box.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(lat1, long1, lat2, long2, units) ⇒ BaseBoundingBox
Returns a new instance of BaseBoundingBox.
5
6
7
8
9
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 5
def initialize(lat1, long1, lat2, long2, units)
@min = {latitude: lat1, longitude: long1}
@max = {latitude: lat2, longitude: long2}
@preferred_units = units
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 50
def method_missing(name, *args)
attribute = name.to_s
if attribute =~ /(width_)(km|kilometers)/
width(:kilometers)
elsif attribute =~ /(width_)(mi|mil|miles)/
width(:miles)
elsif attribute =~ /(height_)(km|kilometers)/
height(:kilometers)
elsif attribute =~ /(height_)(mi|mil|miles)/
height(:miles)
elsif attribute =~ /(min|minimum)_(lat|latitude)/
min_lat
elsif attribute =~ /(min|minimum)_(lon|long|longitude)/
min_long
elsif attribute =~ /(max|maximum)_(lat|latitude)/
max_lat
elsif attribute =~ /(max|maximum)_(lon|long|longitude)/
max_long
end
end
|
Instance Attribute Details
#max ⇒ Object
Returns the value of attribute max.
3
4
5
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 3
def max
@max
end
|
#min ⇒ Object
Returns the value of attribute min.
3
4
5
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 3
def min
@min
end
|
#preferred_units ⇒ Object
Returns the value of attribute preferred_units.
3
4
5
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 3
def preferred_units
@preferred_units
end
|
Instance Method Details
#fetch(property) ⇒ Object
45
46
47
48
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 45
def fetch(property)
raise KeyError unless self.respond_to?(property)
self.send(property)
end
|
#height(units = @preferred_units) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 22
def height(units = @preferred_units)
BB.send("distance_#{units}".to_sym, {latitude: @max[:latitude],
longitude: @max[:longitude]},
{latitude: @min[:latitude],
longitude: @max[:longitude]})
end
|
#max_lat ⇒ Object
37
38
39
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 37
def max_lat
@max[:latitude]
end
|
#max_long ⇒ Object
41
42
43
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 41
def max_long
@max[:longitude]
end
|
#min_lat ⇒ Object
29
30
31
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 29
def min_lat
@min[:latitude]
end
|
#min_long ⇒ Object
33
34
35
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 33
def min_long
@min[:longitude]
end
|
#side_length ⇒ Object
11
12
13
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 11
def side_length
self.send("side_length_#{preferred_units}".to_sym)
end
|
#width(units = @preferred_units) ⇒ Object
15
16
17
18
19
20
|
# File 'lib/bounding_boxes/base_bounding_box.rb', line 15
def width(units = @preferred_units)
BB.send("distance_#{units}".to_sym, {latitude: @max[:latitude],
longitude: @max[:longitude]},
{latitude: @max[:latitude],
longitude: @min[:longitude]})
end
|