OSDN Git Service

arc.url for mmdfile
authornomeu <nomeu@users.sourceforge.jp>
Sat, 26 Jun 2010 16:59:58 +0000 (01:59 +0900)
committernomeu <nomeu@users.sourceforge.jp>
Sat, 26 Jun 2010 16:59:58 +0000 (01:59 +0900)
app/models/arc.rb
spec/models/arc_spec.rb

index 3559bea..df619f8 100644 (file)
@@ -6,20 +6,38 @@ class Arc < ActiveRecord::Base
   has_many :arc_thumbs
   has_many :thumbs, :through => :arc_thumbs
 
-  def site
-    "http://bytatsu.net/uploader/mikumikudance"
+  def location_code
+    /([a-z]+)/.match(code).to_a[1]
   end
 
-  def url
-    if locked?
-      "#{site}/upload.cgi?mode=dl&file=#{number}"
-    else
-      "#{site}/src/#{code}.#{extname}"
+  def number
+    /([0-9]+)/.match(code).to_a[1].to_i
+  end
+
+  def site
+    case location_code
+    when "up"
+      "http://bytatsu.net/uploader/mikumikudance"
+    when "file"
+      "http://loda.jp/mmdfile"
     end
   end
 
-  def number
-    code[2..-1].to_i
+  def url
+    case location_code
+    when "up"
+      if locked?
+        "#{site}/upload.cgi?mode=dl&file=#{number}"
+      else
+        "#{site}/src/#{code}.#{extname}"
+      end
+    when "file"
+      if locked?
+        "#{site}/?mode=pass&idd=#{number}"
+      else
+        "#{site}/?id=#{number}"
+      end
+    end
   end
 
   class Search
index ba62d35..a10450b 100644 (file)
@@ -10,6 +10,17 @@ end
 
 describe Arc do
   #
+  # location_code
+  #
+  it do
+    arc = Arc.new(:code => 'up0675', :extname => 'zip')
+    arc.location_code.should == 'up'
+  end
+  it do
+    arc = Arc.new(:code => 'file0121', :extname => 'zip', :locked => 1)
+    arc.location_code.should == 'file'
+  end
+  #
   # url
   #
   it do
@@ -28,6 +39,14 @@ describe Arc do
     arc = Arc.new(:code => 'up0621', :extname => 'zip', :locked => 1)
     arc.url.should == 'http://bytatsu.net/uploader/mikumikudance/upload.cgi?mode=dl&file=621'
   end
+  it do
+    arc = Arc.new(:code => 'file0121', :extname => 'zip')
+    arc.url.should == 'http://loda.jp/mmdfile/?id=121'
+  end
+  it do
+    arc = Arc.new(:code => 'file0120', :extname => 'zip', :locked => 1)
+    arc.url.should == 'http://loda.jp/mmdfile/?mode=pass&idd=120'
+  end
   #
   # number
   #