Class: SimpleGeolocation::Location

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(attributes = {}) ⇒ Location

Returns a new instance of Location.

Raises:

  • (ArgumentError)


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