Class: Location

Inherits:
Weatherzone::Resource show all
Defined in:
lib/weatherzone/resources/location.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Weatherzone::Resource

has_attribute, has_elements, inherited, #settings

Instance Attribute Details

#typeObject (readonly)

override base ruby Object#type



36
37
38
# File 'lib/weatherzone/resources/location.rb', line 36

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object



99
100
101
# File 'lib/weatherzone/resources/location.rb', line 99

def <=>(other)
  self.name <=> other.name
end

#current_conditionsObject



46
47
48
# File 'lib/weatherzone/resources/location.rb', line 46

def current_conditions
  @current_conditions ||= conditions.first
end

#current_district_forecastObject



50
51
52
# File 'lib/weatherzone/resources/location.rb', line 50

def current_district_forecast
  @current_district_forecast ||= district_forecasts.first
end

#current_district_forecast_precisObject



54
55
56
# File 'lib/weatherzone/resources/location.rb', line 54

def current_district_forecast_precis
  current_district_forecast ? current_district_forecast.precis : "District forecast unavailable"  
end

#current_forecastObject



42
43
44
# File 'lib/weatherzone/resources/location.rb', line 42

def current_forecast
  @current_forecast ||= forecasts.first
end

#current_marine_forecastObject



74
75
76
# File 'lib/weatherzone/resources/location.rb', line 74

def current_marine_forecast
  @marine_forecast ||= marine_forecasts.first
end

#current_state_forecastObject



58
59
60
# File 'lib/weatherzone/resources/location.rb', line 58

def current_state_forecast
  @current_state_forecast ||= state_forecasts.first
end

#current_state_forecast_precisObject



62
63
64
# File 'lib/weatherzone/resources/location.rb', line 62

def current_state_forecast_precis
  current_state_forecast ? current_state_forecast.precis : "State forecast unavailable"
end

#current_synoptic_chartObject



66
67
68
# File 'lib/weatherzone/resources/location.rb', line 66

def current_synoptic_chart
  synoptic_chart.first
end

#current_synoptic_chart_textObject



70
71
72
# File 'lib/weatherzone/resources/location.rb', line 70

def current_synoptic_chart_text
  current_synoptic_chart ? current_synoptic_chart.text : "Synoptic chart unavailable"
end

#historical_observations_shifted_to_nearest_half_hourObject



78
79
80
81
82
83
84
85
# File 'lib/weatherzone/resources/location.rb', line 78

def historical_observations_shifted_to_nearest_half_hour
  obs_to_shift = historical_observations.uniq.reverse
  historical_observations.each do |ho|
    break if ho.is_on_the_half_hour?
    obs_to_shift.shift
  end
  obs_to_shift
end

#hourly_observationsObject



87
88
89
# File 'lib/weatherzone/resources/location.rb', line 87

def hourly_observations
  historical_observations.uniq.reverse.select { |ho| ho.is_on_the_hour? }    
end

#idObject



38
39
40
# File 'lib/weatherzone/resources/location.rb', line 38

def id
  code
end

#positionObject



91
92
93
# File 'lib/weatherzone/resources/location.rb', line 91

def position
  "(#{self.lat}&deg;S, #{self.long}&deg;E, #{self.elevation}m AMSL)"
end

#url_slugObject



95
96
97
# File 'lib/weatherzone/resources/location.rb', line 95

def url_slug
  self.name.parameterize
end