OSDN Git Service

refactored
authornomeu <nomeu@nomeu.org>
Sat, 12 Jun 2010 18:18:02 +0000 (03:18 +0900)
committernomeu <nomeu@nomeu.org>
Sat, 12 Jun 2010 18:18:02 +0000 (03:18 +0900)
bin/read-upl.rb
lib/scrap.rb [new file with mode: 0644]

index 6f36dd1..94e428b 100644 (file)
@@ -1,76 +1,7 @@
 #!ruby
 # vim: fileencoding=utf-8
-require 'nkf'
-
-class Scrap
-  def match(line)
-    @md = @row_re.match(line)
-  end
-
-  def row
-    raise
-  end
-
-  def encode(str)
-    str && NKF.nkf('-Sw', str)
-  end
-
-  def encode_to_sjis(str)
-    str && NKF.nkf('-Ws', str)
-  end
-end
-
-class Scrap_mmd < Scrap
-  def initialize
-    @row_re = %r(</td><td><a href="(.+?)">(.+?)</a></td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td></tr>)
-    @key_re = Regexp.new(Regexp.escape("<font color=\"#FF0000\">[DLKey] </font>"))
-    @password_re = Regexp.new(Regexp.escape("<font color=\"#FF0000\">*</font>"))
-  end
-
-  def row
-    _, href, name, comment, size, date, mime, orig = @md.to_a
-    comment.sub!(@key_re, '')
-    comment.sub!(@password_re, '')
-    [ name, comment, size, date, orig ]
-  end
-end
-
-class Scrap_mmdfile < Scrap
-  def initialize
-    @row_re = %r(<td>\[<a href="(.+?)" >(.+?)</a>\]</td><td>(.+?) <a href="(?:.+?)">(?:.+?)</a></td><td class="size">(.+?)</td><td class="date">(.+?)</td><td class="orig"><span class="orig">(.+?)</span></td>)
-    @key_re = Regexp.new(Regexp.escape("<strong class=\"key\">[P]</strong> "))
-  end
-
-  def row
-    _, href, name, comment, size, date, orig = @md.to_a
-    comment.sub!(@key_re, '')
-    [ name, comment, size, date, orig ]
-  end
-end
-
-class Scrap_mmdacc1 < Scrap
-  def initialize
-    @row_re = %r(<td align=center>\[<a href='(.+?)' target='_new'>(.+?)</a>\]</td><td>(.+?)</td><td align=right>(.+?)</td><td align=center>(.+?)</td><td>(.+))
-  end
-
-  def row
-    _, href, name, comment, size, date, orig = @md.to_a
-    [ name, encode(comment), size, date, encode(orig) ]
-  end
-end
-
-class Scrap_mmdacc2 < Scrap
-  def initialize
-    @row_re = %r(</td><td><a href="(.+?)">(.+?)</a></td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td class="down_max">(.+?)</td></tr>)
-    @key_re = Regexp.new(Regexp.escape(encode_to_sjis("<font color=\"#FF0000\">[パス設定] </font>")))
-  end
-
-  def row
-    _, href, name, comment, size, date = @md.to_a
-    comment.sub!(@key_re, '')
-    [ name, encode(comment), size, encode(date) ]
-  end
-end
+$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
+require 'scrap'
 
 location = ARGV.shift || 'mmd'
 
diff --git a/lib/scrap.rb b/lib/scrap.rb
new file mode 100644 (file)
index 0000000..05f8967
--- /dev/null
@@ -0,0 +1,72 @@
+# vim: fileencoding=utf-8
+require 'nkf'
+
+class Scrap
+  def match(line)
+    @md = @row_re.match(line)
+  end
+
+  def row
+    raise
+  end
+
+  def encode(str)
+    str && NKF.nkf('-Sw', str)
+  end
+
+  def encode_to_sjis(str)
+    str && NKF.nkf('-Ws', str)
+  end
+end
+
+class Scrap_mmd < Scrap
+  def initialize
+    @row_re = %r(</td><td><a href="(.+?)">(.+?)</a></td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td></tr>)
+    @key_re = Regexp.new(Regexp.escape("<font color=\"#FF0000\">[DLKey] </font>"))
+    @password_re = Regexp.new(Regexp.escape("<font color=\"#FF0000\">*</font>"))
+  end
+
+  def row
+    _, href, name, comment, size, date, mime, orig = @md.to_a
+    comment.sub!(@key_re, '')
+    comment.sub!(@password_re, '')
+    [ name, comment, size, date, orig ]
+  end
+end
+
+class Scrap_mmdfile < Scrap
+  def initialize
+    @row_re = %r(<td>\[<a href="(.+?)" >(.+?)</a>\]</td><td>(.+?) <a href="(?:.+?)">(?:.+?)</a></td><td class="size">(.+?)</td><td class="date">(.+?)</td><td class="orig"><span class="orig">(.+?)</span></td>)
+    @key_re = Regexp.new(Regexp.escape("<strong class=\"key\">[P]</strong> "))
+  end
+
+  def row
+    _, href, name, comment, size, date, orig = @md.to_a
+    comment.sub!(@key_re, '')
+    [ name, comment, size, date, orig ]
+  end
+end
+
+class Scrap_mmdacc1 < Scrap
+  def initialize
+    @row_re = %r(<td align=center>\[<a href='(.+?)' target='_new'>(.+?)</a>\]</td><td>(.+?)</td><td align=right>(.+?)</td><td align=center>(.+?)</td><td>(.+))
+  end
+
+  def row
+    _, href, name, comment, size, date, orig = @md.to_a
+    [ name, encode(comment), size, date, encode(orig) ]
+  end
+end
+
+class Scrap_mmdacc2 < Scrap
+  def initialize
+    @row_re = %r(</td><td><a href="(.+?)">(.+?)</a></td><td>(.+?)</td><td>(.+?)</td><td>(.+?)</td><td class="down_max">(.+?)</td></tr>)
+    @key_re = Regexp.new(Regexp.escape(encode_to_sjis("<font color=\"#FF0000\">[パス設定] </font>")))
+  end
+
+  def row
+    _, href, name, comment, size, date = @md.to_a
+    comment.sub!(@key_re, '')
+    [ name, encode(comment), size, encode(date) ]
+  end
+end