Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

merging data before sending to processor

  • Loading branch information...
commit bbe69417b17c912fc88535f9d10637c6d5b199ac 1 parent 8d19ae8
@mattetti authored
Showing with 31 additions and 21 deletions.
  1. +9 −5 processors/episode_summary.rb
  2. +22 −16 runner.rb
View
14 processors/episode_summary.rb
@@ -13,11 +13,7 @@ module EpisodeSummary
def process(items, format=:html)
if format == :html
output = html_header + "\n"
- if items[0] && items[0].show_name
- output += items.sort_by(&:show_name).map{|i| html_episode_summary(i)}.join("\n")
- else
- output += items.sort_by(&:title).map{|i| html_episode_summary(i)}.join("\n")
- end
+ output += sorted_summaries(items, :show_name, :title).join("\n")
output += html_footer
output
elsif format == :json
@@ -27,6 +23,14 @@ def process(items, format=:html)
end
end
+ def sorted_summaries(items, by_attribute, fallback=nil)
+ fallback_value = ->(item){ fallback ? item.send(fallback).to_s : 'zzzzzzzz' }
+ sorted = items.sort do |a,b|
+ (a.show_name || fallback_value.call(a)) <=> (b.show_name || fallback_value.call(b))
+ end
+ sorted.map{|i| html_episode_summary(i) }
+ end
+
def html_header
<<-EOS
<!DOCTYPE html>
View
38 runner.rb
@@ -10,21 +10,27 @@
FileUtils.mkdir_p('output')
-### FranceTV ###
-# Scrap
-episodes = FranceTVJeunesse.run
-# 1st processor
-filtered_episodes = episodes #EpisodeFilter.process(episodes, "config/episode_filter.yml")
-# 2nd processor
-summary = EpisodeSummary.process(filtered_episodes)
-# 3rd processor
-destination = File.join(File.expand_path(File.dirname(__FILE__)), "output", "francetv_summary_#{Time.now.strftime("%Y-%m-%d")}.html")
-puts ToFile.process(summary, destination)
+#### FranceTV ###
+## Scrap
+#episodes = FranceTVJeunesse.run
+## 1st processor
+#filtered_episodes = episodes #EpisodeFilter.process(episodes, "config/episode_filter.yml")
+## 2nd processor
+#summary = EpisodeSummary.process(filtered_episodes)
+## 3rd processor
+#destination = File.join(File.expand_path(File.dirname(__FILE__)), "output", "francetv_summary_#{Time.now.strftime("%Y-%m-%d")}.html")
+#puts ToFile.process(summary, destination)
-### eztv.it ###
-# Scrap
-episodes = EzTV.run
+#### eztv.it ###
+## Scrap
+#episodes = EzTV.run
+#summary = EpisodeSummary.process(episodes)
+## 3rd processor
+#destination = File.join(File.expand_path(File.dirname(__FILE__)), "output", "eztv_summary_#{Time.now.strftime("%Y-%m-%d")}.html")
+#puts ToFile.process(summary, destination)
+
+# mixed summary
+episodes = FranceTVJeunesse.run + EzTV.run
summary = EpisodeSummary.process(episodes)
-# 3rd processor
-destination = File.join(File.expand_path(File.dirname(__FILE__)), "output", "eztv_summary_#{Time.now.strftime("%Y-%m-%d")}.html")
-puts ToFile.process(summary, destination)
+destination = File.join(File.expand_path(File.dirname(__FILE__)), "output", "summary_#{Time.now.strftime("%Y-%m-%d")}.html")
+`open #{ToFile.process(summary, destination)}`
Please sign in to comment.
Something went wrong with that request. Please try again.