Sha256: 8fc091de56d4f8f3443590fbae9f3532ce5c4e8a84e58c6d8eca3c7ef0cdc9f6

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

class Adventures::Adventure

	attr_accessor :title, :location, :url, :suggested_activities, :skill_level, :season, :trail_type, :rt_distance, :elevation_gain, :summary, :description

	@@all = []

	def self.new_from_scrape(a)
		self.new(
			a.css("div.info h3.title").text,
			a.css("div.info p.location").text.strip,
			"https://www.theoutbound.com/#{a.css("a").attribute("href").text}"
		)
	end

	def initialize(title = nil, location = nil, url = nil)
		@title = title
		@location = location
		@url = url
		@@all << self
	end

	def self.all
		@@all
	end

	def self.find(id)
		self.all[id -1]
	end

	def doc
		@doc ||= Nokogiri::HTML(open(self.url))
	end

	def suggested_activities
		@suggested_activities ||= doc.xpath("//div[@class='keylineb m2y']/ul/li[1]/p[2]").text
	end

	def skill_level
		@skill_level ||= doc.xpath("//div[@class='keylineb m2y']/ul/li[2]/p[2]").text
	end

	def season
		@season ||= doc.xpath("//div[@class='keylineb m2y']/ul/li[3]/p[2]").text
	end

	def trail_type
		@trail_type ||= doc.xpath("//div[@class='keylineb m2y']/ul/li[4]/p[2]").text
	end

	def rt_distance
		@rt_distance ||= doc.xpath("//div[@class='keylineb m2y']/ul/li[5]/p[2]").text
	end

	def elevation_gain
		@elevation_gain ||= doc.xpath("//div[@class='keylineb m2y']/ul/li[6]/p[2]").text
	end

	def summary
		@summary ||= doc.xpath("//div[@class='section summary blurb pad2b']/p").text
	end

	def description
		@description ||= doc.xpath("//span[@class='adventure-description']/p").collect { |para|
			para.text
		}.join("\n\n")
	end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
adventures-0.1.0 lib/adventures/adventure.rb