OSDN Git Service

location.create_arc
authornomeu <nomeu@nomeu.org>
Sat, 12 Jun 2010 18:36:26 +0000 (03:36 +0900)
committernomeu <nomeu@nomeu.org>
Sat, 12 Jun 2010 18:36:26 +0000 (03:36 +0900)
bin/load-arcs.rb
lib/location.rb

index 61fd0f1..2a77130 100644 (file)
@@ -4,6 +4,7 @@ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
 require 'connection'
 require 'location'
 require 'arc'
+require 'scrap'
 
 location_code = ARGV.shift || 'mmd'
 location = Location.find_by_code(location_code)
@@ -12,26 +13,13 @@ unless location
   exit
 end
 
-while line = gets
-  name, summary, size, date, origname = line.chomp.split(/\t/)
-  md = /\.(.+)\z/.match(name)
-  extname = md[1]
-  code = File.basename(name, '.' + extname)
-  case location.code
-  when 'mmd'
-    #
-  when 'mmdfile'
-    code = 'file%04d' % code.to_i
-  when 'mmdacc1'
-    code = 'mini%04d' % code.to_i
-  when 'mmdacc2'
-    code = code[3..-1]
-  end
-  arc = Arc.find_by_code(code)
-  if arc
-    puts "found code: #{code}"
-    next
+scrap = Scrap.find_by_location(location.code)
+
+ent = "/Volumes/uploader/src/#{location.code}/index.html"
+open(ent) do |f|
+  while line = f.gets
+    if scrap.match(line)
+      location.create_arc *scrap.row
+    end
   end
-  puts "Arc.create code: #{code}"
-  arc = Arc.create(:code => code, :extname => extname, :location => location, :summary => summary, :origname => origname)
 end
index e3acd90..d937c0a 100644 (file)
@@ -1,2 +1,26 @@
 class Location < ActiveRecord::Base
+  has_many :arcs
+
+  def create_arc(name, summary, size, date, origname)
+    md = /\.(.+)\z/.match(name)
+    extname = md[1]
+    code = File.basename(name, '.' + extname)
+    case self.code
+    when 'mmd'
+      #
+    when 'mmdfile'
+      code = 'file%04d' % code.to_i
+    when 'mmdacc1'
+      code = 'mini%04d' % code.to_i
+    when 'mmdacc2'
+      code = code[3..-1]
+    end
+    arc = Arc.find_by_code(code)
+    if arc
+      puts "found code: #{code}"
+      return
+    end
+    puts "arcs.create code: #{code}"
+    arc = arcs.create(:code => code, :extname => extname, :summary => summary, :origname => origname)
+  end
 end