From 1724c1c533a880fa3a52ef4f191858a8f3bad566 Mon Sep 17 00:00:00 2001 From: nomeu Date: Fri, 19 Oct 2012 17:50:33 +0900 Subject: [PATCH] refactored --- app/models/site.rb | 10 ++++++++++ bin/load-arc_thumbs.rb | 8 +++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/models/site.rb b/app/models/site.rb index f493001..8712a97 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -12,6 +12,11 @@ class Site < ActiveGroonga::Base end end + def locked_path_re + @_locked_path_re ||= + locked_path_pattern ? Regexp.new(Regexp.escape(url) + locked_path_pattern) : nil + end + def path_pattern case self.code when 'mmd', 'mmd3dcu' @@ -27,6 +32,11 @@ class Site < ActiveGroonga::Base end end + def path_re + @_path_re ||= + path_pattern ? Regexp.new(Regexp.escape(url) + path_pattern) : nil + end + def generate_locked_arc_code(name) case self.code when 'mmd' diff --git a/bin/load-arc_thumbs.rb b/bin/load-arc_thumbs.rb index 8c68e86..bb8d9c0 100644 --- a/bin/load-arc_thumbs.rb +++ b/bin/load-arc_thumbs.rb @@ -28,17 +28,15 @@ thumbs = Thumb.all thumbs.each do |thumb| # puts "# #{thumb.video_id}" sites.each do |site| - path_re = Regexp.new(Regexp.escape(site.url) + site.path_pattern) - if md = path_re.match(thumb.description) + if md = site.path_re.match(thumb.description) name = md[1] code, extname = site.generate_arc_code_and_extname(name) puts [ thumb.video_id, "", code ].join("\t") link(thumb, code) end - next unless site.locked_path_pattern - locked_path_re = Regexp.new(Regexp.escape(site.url) + site.locked_path_pattern) - if md = locked_path_re.match(thumb.description) + next unless site.locked_path_re + if md = site.locked_path_re.match(thumb.description) name = md[1] code = site.generate_locked_arc_code(name) puts [ thumb.video_id, "locked", code ].join("\t") -- 2.11.0