OSDN Git Service

refactored
authornomeu <nomeu@users.sourceforge.jp>
Fri, 19 Oct 2012 08:50:33 +0000 (17:50 +0900)
committernomeu <nomeu@users.sourceforge.jp>
Fri, 19 Oct 2012 08:50:33 +0000 (17:50 +0900)
app/models/site.rb
bin/load-arc_thumbs.rb

index f493001..8712a97 100644 (file)
@@ -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'
index 8c68e86..bb8d9c0 100644 (file)
@@ -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")