Class: PodcastFinder::DataImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/podcast_finder/importer.rb

Class Method Summary collapse

Class Method Details

.import_categories(index_url) ⇒ Object



3
4
5
6
# File 'lib/podcast_finder/importer.rb', line 3

def self.import_categories(index_url)
  category_data = PodcastFinder::Scraper.new.scrape_category_list(index_url)
  PodcastFinder::Category.create_from_collection(category_data)
end

.import_description(podcast) ⇒ Object



40
41
42
43
44
# File 'lib/podcast_finder/importer.rb', line 40

def self.import_description(podcast)
  if podcast.description.nil?
    podcast.description = PodcastFinder::Scraper.new.get_podcast_description(podcast.url)
  end
end

.import_episodes(podcast) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/podcast_finder/importer.rb', line 46

def self.import_episodes(podcast)
  if podcast.episodes == []
    episode_list = PodcastFinder::Scraper.new.scrape_episodes(podcast.url)
    episode_list.each do |episode_hash|
      episode = PodcastFinder::Episode.new(episode_hash)
      podcast.add_episode(episode)
    end
  end
end

.import_podcast_data(category) ⇒ Object



8
9
10
11
12
# File 'lib/podcast_finder/importer.rb', line 8

def self.import_podcast_data(category)
  podcast_array = PodcastFinder::Scraper.new.scrape_podcasts(category.url)
  self.import_stations(podcast_array)
  self.import_podcasts(podcast_array, category)
end

.import_podcasts(podcast_array, category) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/podcast_finder/importer.rb', line 25

def self.import_podcasts(podcast_array, category)
  podcast_array.each do |podcast_hash|
    check_podcast = podcast_hash[:name]
    if PodcastFinder::Podcast.find_by_name(check_podcast).nil?
      podcast = PodcastFinder::Podcast.new(podcast_hash)
      category.add_podcast(podcast)
      station = PodcastFinder::Station.find_by_name(podcast_hash[:station])
      station.add_podcast(podcast)
    else
      podcast = PodcastFinder::Podcast.find_by_name(check_podcast)
      category.add_podcast(podcast)
    end
  end
end

.import_stations(podcast_array) ⇒ Object

helper methods for import_podcast_data



16
17
18
19
20
21
22
23
# File 'lib/podcast_finder/importer.rb', line 16

def self.import_stations(podcast_array)
  podcast_array.each do |podcast_hash|
    check_station = podcast_hash[:station]
    if PodcastFinder::Station.find_by_name(check_station).nil?
      station = PodcastFinder::Station.new(podcast_hash)
    end
  end
end