spreader 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/spreader.rb +7 -7
- metadata +1 -1
data/lib/spreader.rb
CHANGED
@@ -19,10 +19,10 @@ class Spreader
|
|
19
19
|
return yield data
|
20
20
|
end
|
21
21
|
|
22
|
-
def xml?(
|
23
|
-
head =
|
24
|
-
while
|
25
|
-
@xml = true if (line.include? '<') &&
|
22
|
+
def xml?(relative_path)
|
23
|
+
head = IO.popen('head -' + IO.popen("wc -l #{relative_path}").gets.split(' ').first + " #{relative_path}")
|
24
|
+
while line = head.gets
|
25
|
+
@xml = true if (line.include? '<') && !@xml
|
26
26
|
end
|
27
27
|
|
28
28
|
return @xml
|
@@ -62,9 +62,9 @@ class Spreader
|
|
62
62
|
load(transform(data, model_name, latitude_field_name, longitude_field_name))
|
63
63
|
end
|
64
64
|
|
65
|
-
def self.seed(
|
65
|
+
def self.seed(relative_path, model_name, latitude_field_name, longitude_field_name)
|
66
66
|
spreader = Spreader.new
|
67
|
-
spreader.transformLoad(spreader.extract(
|
68
|
-
spreader.transformLoad(spreader.extract(
|
67
|
+
spreader.transformLoad(spreader.extract(relative_path){|data| XML::Reader.file("#{data}", :options => XML::Parser::Options::NOBLANKS | XML::Parser::Options::NOENT)}, model_name, latitude_field_name, longitude_field_name) if spreader.xml?(relative_path)
|
68
|
+
spreader.transformLoad(spreader.extract(relative_path){|data| File.open("#{data}")}, model_name, latitude_field_name, longitude_field_name) if !spreader.xml?(relative_path)
|
69
69
|
end
|
70
70
|
end
|