class WashingtonHikes::Hike

Attributes

description[RW]
elevation_gain[RW]
features[RW]
length[RW]
name[RW]
rating[RW]
region[RW]
type[RW]
url[RW]

Public Class Methods

all() click to toggle source

All hikes in class

# File lib/washington_hikes/hike.rb, line 24
def self.all
  @@all
end
create_from_wta() click to toggle source

Create new hike instances with attributes gathered from scraped WTA page

# File lib/washington_hikes/hike.rb, line 15
def self.create_from_wta
  hikes = WashingtonHikes::Scraper.scrape_wta_hike_list
  hikes.each do |hike| 
    hike[:region] = WashingtonHikes::Region.find_or_create_region_by_name(hike[:region])
    self.new(hike)
  end
end
new(attributes) click to toggle source

Initialize a hike with a hash of attributes, and connect hike and region instances

# File lib/washington_hikes/hike.rb, line 8
def initialize(attributes)
  attributes.each {|key, value| self.send(("#{key}="), value)}
  @region.add_hike(self)
  @@all << self
end

Public Instance Methods

add_hike_details() click to toggle source

Add additional properties to hikes users want to see details on

# File lib/washington_hikes/hike.rb, line 29
def add_hike_details
  scraped_details = WashingtonHikes::Scraper.scrape_wta_hike_description(self.url)
  scraped_details.each {|key, value| self.send(("#{key}="), value)}
end