Class: Location
- Inherits:
-
Object
- Object
- Location
- Defined in:
- lib/flickru/location.rb
Constant Summary collapse
- DEFAULT_ACCURACY =
"street"
- COORD_PATTERN =
"-?[0-9]+\.?[0-9]*"
Instance Attribute Summary collapse
-
#accuracy ⇒ Object
Returns the value of attribute accuracy.
-
#latitude ⇒ Object
Returns the value of attribute latitude.
-
#longitude ⇒ Object
Returns the value of attribute longitude.
-
#name ⇒ Object
Returns the value of attribute name.
-
#place ⇒ Object
Returns the value of attribute place.
Instance Method Summary collapse
-
#initialize(photo) ⇒ Location
constructor
A new instance of Location.
- #nil? ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(photo) ⇒ Location
Returns a new instance of Location.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/flickru/location.rb', line 19 def initialize photo dir = File.basename File.dirname(photo) name, place, accuracy = Location.parse dir raise RuntimeError, "#{dir}, name not provided" if name.nil? @name = name begin @place = place.nil? ? name : place @latitude, @longitude = Location.locate @place @accuracy = Location.s_to_accuracy(accuracy ? accuracy : DEFAULT_ACCURACY) rescue RuntimeError raise if place raise RuntimeError, "location #{name} not found" if accuracy @place, @latitude, @longitude, @accuracy = nil # no location end end |
Instance Attribute Details
#accuracy ⇒ Object
Returns the value of attribute accuracy.
17 18 19 |
# File 'lib/flickru/location.rb', line 17 def accuracy @accuracy end |
#latitude ⇒ Object
Returns the value of attribute latitude.
17 18 19 |
# File 'lib/flickru/location.rb', line 17 def latitude @latitude end |
#longitude ⇒ Object
Returns the value of attribute longitude.
17 18 19 |
# File 'lib/flickru/location.rb', line 17 def longitude @longitude end |
#name ⇒ Object
Returns the value of attribute name.
17 18 19 |
# File 'lib/flickru/location.rb', line 17 def name @name end |
#place ⇒ Object
Returns the value of attribute place.
17 18 19 |
# File 'lib/flickru/location.rb', line 17 def place @place end |
Instance Method Details
#nil? ⇒ Boolean
35 36 37 38 39 40 41 |
# File 'lib/flickru/location.rb', line 35 def nil? Ruby.assert("@accuracy.nil? implies @latitude.nil? and @longitude.nil?") { @accuracy.nil? or not (@latitude.nil? and @longitude.nil?) } @accuracy.nil? end |
#to_s ⇒ Object
43 44 45 46 47 |
# File 'lib/flickru/location.rb', line 43 def to_s place = @place.nil? ? "an undefined place" : @place "#{@name.black} at #{place.black} (~#{accuracy_to_s.black}) " + "on lat: #{@latitude.black}, lon: #{@longitude.black}" end |