Class: SimpleGeolocation::Location
- Inherits:
-
Object
- Object
- SimpleGeolocation::Location
- Defined in:
- lib/simple_geolocation/location.rb
Constant Summary collapse
- ATTRIBUTES =
[:lat, :lng, :city, :state, :country, :provider, :zip, :street, :district, :number]
Instance Method Summary collapse
- #completeness(attributes = ATTRIBUTES) ⇒ Object
-
#initialize(attributes = {}) ⇒ Location
constructor
A new instance of Location.
Constructor Details
#initialize(attributes = {}) ⇒ Location
Returns a new instance of Location.
8 9 10 11 12 13 14 |
# File 'lib/simple_geolocation/location.rb', line 8 def initialize(attributes = {}) unknown_attributes = attributes.keys.reject { |k| ATTRIBUTES.include?(k) } raise ArgumentError, "Unknown parameters: #{unknown_attributes.join(', ')}" unless unknown_attributes.empty? attributes.each do |k, v| send("#{k}=", v) end end |
Instance Method Details
#completeness(attributes = ATTRIBUTES) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/simple_geolocation/location.rb', line 16 def completeness(attributes = ATTRIBUTES) total = attributes.size used = attributes.reject {|attr| send(attr).blank? }.size return 100 if used >= total (used.to_f / total.to_f * 100.0).to_i end |