Class: Wunderground::Location

Inherits:
Object
  • Object
show all
Defined in:
lib/wunderground/location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Location

Returns a new instance of Location.

Raises:

  • (ArgumentError)


5
6
7
8
9
10
# File 'lib/wunderground/location.rb', line 5

def initialize(options = {})
  raise ArgumentError, "No Location Options Provided" if options.empty?
  options.each do |key, value|
    instance_variable_set("@#{key}".to_sym, value)
  end
end

Instance Attribute Details

#airportObject

Returns the value of attribute airport.



3
4
5
# File 'lib/wunderground/location.rb', line 3

def airport
  @airport
end

#autoipObject

Returns the value of attribute autoip.



3
4
5
# File 'lib/wunderground/location.rb', line 3

def autoip
  @autoip
end

#cityObject

Returns the value of attribute city.



3
4
5
# File 'lib/wunderground/location.rb', line 3

def city
  @city
end

#countryObject

Returns the value of attribute country.



3
4
5
# File 'lib/wunderground/location.rb', line 3

def country
  @country
end

#latObject

Returns the value of attribute lat.



3
4
5
# File 'lib/wunderground/location.rb', line 3

def lat
  @lat
end

#longObject

Returns the value of attribute long.



3
4
5
# File 'lib/wunderground/location.rb', line 3

def long
  @long
end

#pwsObject

Returns the value of attribute pws.



3
4
5
# File 'lib/wunderground/location.rb', line 3

def pws
  @pws
end

#stateObject

Returns the value of attribute state.



3
4
5
# File 'lib/wunderground/location.rb', line 3

def state
  @state
end

#zipObject

Returns the value of attribute zip.



3
4
5
# File 'lib/wunderground/location.rb', line 3

def zip
  @zip
end

Instance Method Details

#locationObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wunderground/location.rb', line 12

def location
  if zip
    zip
  elsif state && city
    "#{state}/#{city.gsub(' ', '_')}"
  elsif country && city
    "#{country.gsub(' ', '_')}/#{city.gsub(' ', '_')}"
  elsif airport
    airport
  elsif lat && long
    "#{lat},#{long}"
  elsif pws
    "pws:#{pws}"
  elsif autoip
    "autoip"
  else
    raise ArgumentError, "Invalid Location Options"
  end
end