Class: WeatherGov::Identifier

Inherits:
Object
  • Object
show all
Defined in:
lib/weather_gov/identifier.rb,
lib/weather_gov/identifier.rb,
lib/weather_gov/identifier/alert.rb,
lib/weather_gov/identifier/point.rb,
lib/weather_gov/identifier/office.rb,
lib/weather_gov/identifier/problem.rb,
lib/weather_gov/identifier/station.rb,
lib/weather_gov/identifier/fire_zone.rb,
lib/weather_gov/identifier/gridpoint.rb,
lib/weather_gov/identifier/county_zone.rb,
lib/weather_gov/identifier/forecast_zone.rb

Defined Under Namespace

Classes: Alert, CountyZone, FireZone, ForecastZone, Gridpoint, Office, Point, Problem, Station

Constant Summary collapse

TYPES =
constants.map { |c| const_get(c) }.select { |c| c.superclass == self }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Identifier

Returns a new instance of Identifier.



19
20
21
# File 'lib/weather_gov/identifier.rb', line 19

def initialize(uri)
  @uri = uri
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



5
6
7
# File 'lib/weather_gov/identifier.rb', line 5

def uri
  @uri
end

Class Method Details

.base_uriObject



15
16
17
# File 'lib/weather_gov/identifier.rb', line 15

def self.base_uri
  API_BASE_URI
end

.parse(uri) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/weather_gov/identifier.rb', line 7

def self.parse(uri)
  TYPES.each do |type|
    return type.new(uri) if uri.start_with?(type.base_uri)
  end

  nil
end

Instance Method Details

#idObject



27
28
29
# File 'lib/weather_gov/identifier.rb', line 27

def id
  uri.sub(/^#{self.class.base_uri}/, "")
end

#to_sObject



23
24
25
# File 'lib/weather_gov/identifier.rb', line 23

def to_s
  id
end