class TopTravelDestinations::Region
Attributes
destinations[RW]
name[RW]
region_url[RW]
Public Class Methods
all()
click to toggle source
# File lib/top_travel_destinations/region.rb, line 30 def self.all @@all end
create_from_array(regions_array)
click to toggle source
# File lib/top_travel_destinations/region.rb, line 14 def self.create_from_array(regions_array) regions_array.each do |region_hash| TopTravelDestinations::Region.new(region_hash) end end
get_regions()
click to toggle source
# File lib/top_travel_destinations/region.rb, line 34 def self.get_regions TopTravelDestinations::Scraper.scrape_regions_array end
new(region_hash)
click to toggle source
# File lib/top_travel_destinations/region.rb, line 7 def initialize(region_hash) self.create_attributes_from_hash(region_hash) self.destinations = [] self.get_destinations self.class.all << self end
Public Instance Methods
add_destinations(destinations_array)
click to toggle source
creates “has many” relationship to instance of Region
# File lib/top_travel_destinations/region.rb, line 63 def add_destinations(destinations_array) destinations_array.each do |destination_hash| destination = TopTravelDestinations::Destination.new(destination_hash) self.destinations << destination destination.region = self end end
create_attribute_from_array(destinations_array)
click to toggle source
# File lib/top_travel_destinations/region.rb, line 26 def create_attribute_from_array(destinations_array) self.destinations = destinations_array end
create_attributes_from_hash(region_hash)
click to toggle source
# File lib/top_travel_destinations/region.rb, line 20 def create_attributes_from_hash(region_hash) region_hash.each do |key, value| self.send(("#{key}="), value) end end
destination_descriptions()
click to toggle source
# File lib/top_travel_destinations/region.rb, line 79 def destination_descriptions destinations_descriptions_array = [] self.destinations.each do |destination| destinations_descriptions_array << destination.description end destinations_descriptions_array end
destination_names()
click to toggle source
# File lib/top_travel_destinations/region.rb, line 71 def destination_names destinations_names_array = [] self.destinations.each do |destination| destinations_names_array << destination.name end destinations_names_array end
get_destinations()
click to toggle source
# File lib/top_travel_destinations/region.rb, line 38 def get_destinations destinations_array = self.scrape_destinations_array self.add_destinations(destinations_array) end
scrape_destinations_array()
click to toggle source
# File lib/top_travel_destinations/region.rb, line 43 def scrape_destinations_array html = open(self.region_url) doc = Nokogiri::HTML(html) destinations_array = [] doc.css("div#WINNERVIEWER").children.each do |destination| name = destination.search("div.mainName a").text description = destination.search("div.descr_lb").text if name != "" && description !="" destinations_array << { :name => name, :description => description} end end #end iterator destinations_array end