class NationalParks::State

Attributes

name[RW]
url[RW]

Public Class Methods

all() click to toggle source
# File lib/national_parks/state.rb, line 32
def self.all
  @@states.sort_by{|state| state.name} # state objects stored in alphabetical order by name
end
find_state(id) click to toggle source
# File lib/national_parks/state.rb, line 40
def self.find_state(id)
  self.all[id.to_i - 1]
end
find_state_by_name(name) click to toggle source
# File lib/national_parks/state.rb, line 36
def self.find_state_by_name(name)
  self.all.detect{|state| state.name.downcase == name.downcase}
end
new(state_attribute_hash = nil) click to toggle source
# File lib/national_parks/state.rb, line 7
def initialize(state_attribute_hash = nil)
  if state_attribute_hash
    state_attribute_hash.each{|key, value| self.send("#{key}=", value)}
  end
  @parks = [] # has many park objects interface
  @@states << self
end

Public Instance Methods

add_park(park) click to toggle source
# File lib/national_parks/state.rb, line 19
def add_park(park) # has many park objects interface
  if !park.is_a?(NationalParks::Park)
    raise InvalidType, "#{park.class} received, Park expected"
  else
    @parks << park unless @parks.include?(park)
    park.state = self unless park.state == self
  end
end
find_park(id) click to toggle source
# File lib/national_parks/state.rb, line 28
def find_park(id)
  parks[id.to_i - 1]
end
parks() click to toggle source
# File lib/national_parks/state.rb, line 15
def parks # has many park objects interface
  @parks.dup.freeze.sort_by{|park| park.name} # park objects of each state object stored in alphabetical order by name
end