onix 0.7.6 → 0.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/CHANGELOG +4 -0
  2. data/lib/onix.rb +1 -1
  3. data/lib/onix/normaliser.rb +14 -8
  4. metadata +2 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v0.7.7 (1st October 2009)
2
+ - optimise sed usage in ONIX::Normaliser. *huge* speed improvement on
3
+ large files.
4
+
1
5
  v0.7.6 (21st September 2009)
2
6
  - provide access to the PackQuantity element
3
7
 
data/lib/onix.rb CHANGED
@@ -16,7 +16,7 @@ module ONIX
16
16
  module Version #:nodoc:
17
17
  Major = 0
18
18
  Minor = 7
19
- Tiny = 6
19
+ Tiny = 7
20
20
 
21
21
  String = [Major, Minor, Tiny].join('.')
22
22
  end
@@ -71,12 +71,14 @@ module ONIX
71
71
  @curfile = dest
72
72
 
73
73
  # remove entities
74
- replace_named_entities(@curfile)
74
+ dest = next_tempfile
75
+ replace_named_entities(@curfile, dest)
76
+ @curfile = dest
75
77
 
76
78
  FileUtils.cp(@curfile, @newfile)
77
79
  end
78
80
 
79
- private
81
+ #private
80
82
 
81
83
  # check the specified app is available on the system
82
84
  #
@@ -133,7 +135,7 @@ module ONIX
133
135
  FileUtils.cp(inpath, outpath)
134
136
  else
135
137
  FileUtils.cp(inpath, outpath)
136
- `sed -i 's/<?xml.*?>/<?xml version=\"1.0\" encoding=\"UTF-8\"?>/' #{outpath}`
138
+ `sed -i 's/<?xml.*?>/<?xml version=\"1.0\" encoding=\"UTF-8\"?>/g' #{outpath}`
137
139
  end
138
140
  elsif src_enc
139
141
  `iconv --from-code=#{src_enc} --to-code=UTF-8 #{inpath} > #{outpath}`
@@ -154,11 +156,15 @@ module ONIX
154
156
  # replace all named entities in the specified file with
155
157
  # numeric entities.
156
158
  #
157
- def replace_named_entities(path)
158
- # TODO: this is horrible. 1500 sed calls.
159
- entity_map.each do |named, numeric|
160
- `sed -i 's/\\&#{named};/\\&#{numeric};/g' #{path}`
161
- end
159
+ def replace_named_entities(src, dest)
160
+ inpath = File.expand_path(src)
161
+ outpath = File.expand_path(dest)
162
+
163
+ cmd = "sed " + entity_map.map do |named, numeric|
164
+ "-e 's/\\&#{named};/\\&#{numeric};/g'"
165
+ end.join(" ") + " #{inpath} > #{outpath}"
166
+ #raise cmd
167
+ `#{cmd}`
162
168
  end
163
169
 
164
170
  # return a named entity to numeric entity mapping, build by extracting
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-22 00:00:00 +10:00
12
+ date: 2009-10-01 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency