oddb2xml 1.0.6 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.0.7 / 20.11.2012
2
+
3
+ * Add -t --tag-suffix option for 'md'
4
+
1
5
  === 1.0.6 / 23.10.2012
2
6
 
3
7
  * Added nonpharma option
data/README.md CHANGED
@@ -1,4 +1,19 @@
1
1
  oddb2xml
2
2
  ========
3
3
 
4
- oddb2xml, create xml files using swissINDEX and BAG-XML
4
+ oddb2xml, creates xml files using swissINDEX, BAG-XML and Swissmedic XLS.
5
+
6
+
7
+ usage
8
+ -----
9
+
10
+ ```
11
+ $ oddb2xml --help
12
+ bin/oddb2xml ver.1.0.6
13
+ Usage:
14
+ oddb2xml [option]
15
+ -c F, --compress=F Compress format F. Currently only 'tar.gz' is available.
16
+ -a T, --append=T Additional target. T is only 'nonpharma' available.
17
+ -t S, --tag-suffix=S XML tag suffix S. default none. Only 'md' is available.
18
+ -h, --help Show this help message.
19
+ ```
data/bin/oddb2xml CHANGED
@@ -13,20 +13,23 @@ def help
13
13
  #$0 ver.#{Oddb2xml::VERSION}
14
14
  Usage:
15
15
  oddb2xml [option]
16
- -c F, --compress=F Compress format F. Currently only 'tar.gz' is available.
17
- -a T, --append=T Additional target. T is only 'nonpharma' available.
18
- -h, --help Show this help message.
16
+ -c F, --compress=F Compress format F. Currently only 'tar.gz' is available.
17
+ -a T, --append=T Additional target. T is only 'nonpharma' available.
18
+ -t S, --tag-suffix=S XML tag suffix S. default none. Only 'md' is available.
19
+ -h, --help Show this help message.
19
20
  EOS
20
21
  end
21
22
 
22
23
  parser = OptionParser.new
23
24
  opts = {
24
- :compress => nil,
25
- :nonpharma => false
25
+ :compress => nil,
26
+ :nonpharma => false,
27
+ :tag_suffix => '',
26
28
  }
27
29
 
28
30
  parser.on('-c v', '--compress v', /tar\.gz/) {|v| opts[:compress] = v }
29
31
  parser.on('-a v', '--append v', /nonpharma/) {|v| opts[:nonpharma] = v }
32
+ parser.on('-t v', '--tag-suffix v', /md/i) {|v| opts[:tag_suffix] = v.upcase }
30
33
  parser.on_tail('-h', '--help') { puts help; exit }
31
34
 
32
35
  args = ARGV.dup
@@ -2,13 +2,27 @@
2
2
 
3
3
  require 'nokogiri'
4
4
 
5
+ module Nokogiri
6
+ module XML
7
+ class Document < Nokogiri::XML::Node
8
+ attr_writer :tag_suffix
9
+ alias :create_element_origin :create_element
10
+ def create_element name, *args, &block
11
+ name += (@tag_suffix || '')
12
+ create_element_origin(name, *args, &block)
13
+ end
14
+ end
15
+ end
16
+ end
17
+
5
18
  module Oddb2xml
6
19
  class Builder
7
- attr_accessor :subject, :index, :items
20
+ attr_accessor :subject, :index, :items, :tag_suffix
8
21
  def initialize
9
- @subject = nil
10
- @index = {}
11
- @items = {}
22
+ @subject = nil
23
+ @index = {}
24
+ @items = {}
25
+ @tag_suffix = ''
12
26
  if block_given?
13
27
  yield self
14
28
  end
@@ -36,6 +50,7 @@ module Oddb2xml
36
50
  seq
37
51
  end
38
52
  _builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
53
+ xml.doc.tag_suffix = @tag_suffix
39
54
  datetime = Time.new.strftime('%FT%T.%7N%z')
40
55
  xml.PRODUCT(
41
56
  'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
@@ -170,6 +185,7 @@ module Oddb2xml
170
185
  objects << object
171
186
  end
172
187
  _builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
188
+ xml.doc.tag_suffix = @tag_suffix
173
189
  datetime = Time.new.strftime('%FT%T.%7N%z')
174
190
  xml.ARTICLE(
175
191
  'xmlns:xsd' => 'http://www.w3.org/2001/XMLSchema',
data/lib/oddb2xml/cli.rb CHANGED
@@ -59,9 +59,10 @@ module Oddb2xml
59
59
  index[lang].merge!(@index[lang][type])
60
60
  end
61
61
  end
62
- builder.subject = sbj
63
- builder.index = index
64
- builder.items = @items
62
+ builder.subject = sbj
63
+ builder.index = index
64
+ builder.items = @items
65
+ builder.tag_suffix = @options[:tag_suffix]
65
66
  end
66
67
  xml = builder.to_xml
67
68
  File.open(file, 'w:utf-8'){ |fh| fh << xml }
@@ -1,3 +1,3 @@
1
1
  module Oddb2xml
2
- VERSION = "1.0.6"
2
+ VERSION = "1.0.7"
3
3
  end
data/spec/cli_spec.rb CHANGED
@@ -2,10 +2,22 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
+ RSpec::Matchers.define :have_option do |option|
6
+ match do |interface|
7
+ key = option.keys.first
8
+ val = option.values.first
9
+ options = interface.instance_variable_get(:@options)
10
+ options[key] == val
11
+ end
12
+ description do
13
+ "have #{option.keys.first} option as #{option.values.first}"
14
+ end
15
+ end
16
+
5
17
  shared_examples_for 'any interface' do
6
18
  it { cli.should respond_to(:run) }
7
19
  it 'should run successfully' do
8
- $stdout.should_receive(:puts).with(/product/)
20
+ $stdout.should_receive(:puts).with(/products/)
9
21
  cli.run
10
22
  end
11
23
  end
@@ -15,18 +27,20 @@ describe Oddb2xml::Cli do
15
27
  before(:each) do
16
28
  setup_server_mocks
17
29
  end
18
- context "when -c tar.gz option is given" do
30
+ context 'when -c tar.gz option is given' do
19
31
  let(:cli) { Oddb2xml::Cli.new({:compress => 'tar.gz', :nonpharma => false}) }
20
- it { cli.instance_variable_get(:@options).should == {:compress => 'tar.gz', :nonpharma => false} }
21
32
  it_behaves_like 'any interface'
22
- it "should create tar.gz file" do
33
+ it 'should have compress option' do
34
+ cli.should have_option(:compress => 'tar.gz')
35
+ end
36
+ it 'should create tar.gz file' do
23
37
  $stdout.should_receive(:puts).with(/Pharma/)
24
38
  cli.run
25
39
  file = Dir.glob('oddb_*.tar.gz').first
26
40
  File.exists?(file).should be_true
27
41
  end
28
- it "should not create any xml file" do
29
- $stdout.should_receive(:puts).with(/Nonpharma/)
42
+ it 'should not create any xml file' do
43
+ $stdout.should_receive(:puts).with(/Pharma/)
30
44
  cli.run
31
45
  Dir.glob('oddb_*.xml').each do |file|
32
46
  File.exists?(file).should be_nil
@@ -38,17 +52,19 @@ describe Oddb2xml::Cli do
38
52
  end
39
53
  end
40
54
  end
41
- context "when -a nonpharma option is given" do
55
+ context 'when -a nonpharma option is given' do
42
56
  let(:cli) { Oddb2xml::Cli.new({:compress => nil, :nonpharma => true}) }
43
- it { cli.instance_variable_get(:@options).should == {:compress => nil, :nonpharma => true} }
44
57
  it_behaves_like 'any interface'
45
- it "should not create any compressed file" do
46
- $stdout.should_receive(:puts).with(/Pharma/)
58
+ it 'should have nonpharma option' do
59
+ cli.should have_option(:nonpharma => true)
60
+ end
61
+ it 'should not create any compressed file' do
62
+ $stdout.should_receive(:puts).with(/NonPharma/)
47
63
  cli.run
48
64
  Dir.glob('oddb_*.tar.gz').first.should be_nil
49
65
  end
50
- it "should create 2 xml files" do
51
- $stdout.should_receive(:puts).with(/Nonpharma/)
66
+ it 'should create 2 xml files' do
67
+ $stdout.should_receive(:puts).with(/NonPharma/)
52
68
  cli.run
53
69
  Dir.glob('oddb_*.xml').each do |file|
54
70
  File.exists?(file).should be_true
@@ -30,7 +30,20 @@ describe Oddb2xml::Compressor do
30
30
  end
31
31
  end
32
32
  context 'successfully' do
33
- it 'pending'
33
+ it 'should create compressed file' do
34
+ File.stub(:unlink).and_return(false)
35
+ @compressor.contents << File.expand_path('../data/oddb_article.xml', __FILE__)
36
+ @compressor.contents << File.expand_path('../data/oddb_product.xml', __FILE__)
37
+ @compressor.finalize!.should == true
38
+ compressed_file = @compressor.instance_variable_get(:@compressed_file)
39
+ File.exists?(compressed_file).should == true
40
+ File.unstub!(:unlink)
41
+ end
42
+ after(:each) do
43
+ Dir.glob('oddb_xml_*.tar.gz').each do |file|
44
+ File.unlink(file) if File.exists?(file)
45
+ end
46
+ end
34
47
  end
35
48
  end
36
49
  end
@@ -4,7 +4,7 @@ require 'spec_helper'
4
4
 
5
5
  shared_examples_for 'any downloader' do
6
6
  # this takes 5 sec. by call for sleep
7
- it 'should count retry times as retrievable or not' do
7
+ it 'should count retry times as retrievable or not', :slow => true do
8
8
  expect {
9
9
  Array.new(3).map do
10
10
  Thread.new do
@@ -35,7 +35,7 @@ describe Oddb2xml::BagXmlDownloader do
35
35
  xml.should =~ /Preparations/
36
36
  xml.should =~ /DescriptionDe/
37
37
  end
38
- it 'should cleanup current directory' do
38
+ it 'should clean up current directory' do
39
39
  xml.should_not raise_error(Timeout::Error)
40
40
  File.exist?('XMLPublications.zip').should be(false)
41
41
  end
@@ -46,19 +46,42 @@ describe Oddb2xml::SwissIndexDownloader do
46
46
  include ServerMockHelper
47
47
  before(:each) do
48
48
  setup_swiss_index_server_mock
49
- @downloader = Oddb2xml::SwissIndexDownloader.new()
50
49
  end
51
- it_behaves_like 'any downloader'
52
- context 'when download_by is called with DE' do
53
- let(:xml) { @downloader.download_by('DE') }
54
- it 'should parse hash to xml' do
55
- xml.should be_a String
56
- xml.length.should_not == 0
50
+ context 'Pharma' do
51
+ before(:each) do
52
+ @downloader = Oddb2xml::SwissIndexDownloader.new(:pharma)
57
53
  end
58
- it 'should return valid xml' do
59
- xml.should =~ /xml\sversion="1.0"/
60
- xml.should =~ /ITEM/
61
- xml.should =~ /PHAR/
54
+ it_behaves_like 'any downloader'
55
+ context 'when download_by is called with DE' do
56
+ let(:xml) { @downloader.download_by('DE') }
57
+ it 'should parse response hash to xml' do
58
+ xml.should be_a String
59
+ xml.length.should_not == 0
60
+ xml.should =~ /xml\sversion="1.0"/
61
+ end
62
+ it 'should return valid xml' do
63
+ xml.should =~ /PHAR/
64
+ xml.should =~ /ITEM/
65
+ end
62
66
  end
63
67
  end
68
+ context 'NonPharma' do
69
+ before(:each) do
70
+ @downloader = Oddb2xml::SwissIndexDownloader.new(:nonpharma)
71
+ end
72
+ it_behaves_like 'any downloader'
73
+ context 'when download_by is called with DE' do
74
+ let(:xml) { @downloader.download_by('DE') }
75
+ it 'should parse response hash to xml' do
76
+ xml.should be_a String
77
+ xml.length.should_not == 0
78
+ xml.should =~ /xml\sversion="1.0"/
79
+ end
80
+ it 'should return valid xml' do
81
+ xml.should =~ /NONPHAR/
82
+ xml.should =~ /ITEM/
83
+ end
84
+ end
85
+ end
86
+
64
87
  end
data/spec/spec_helper.rb CHANGED
@@ -36,28 +36,30 @@ module ServerMockHelper
36
36
  :body => stub_response)
37
37
  end
38
38
  def setup_swiss_index_server_mock
39
- # wsdl
40
- stub_wsdl_url = 'https://index.ws.e-mediat.net/Swissindex/Pharma/ws_Pharma_V101.asmx?WSDL'
41
- stub_response = File.read(File.expand_path('../data/wsdl.xml', __FILE__))
42
- stub_request(:get, stub_wsdl_url).
43
- with(:headers => {
44
- 'Accept' => '*/*',
45
- 'User-Agent' => 'Ruby'}).
46
- to_return(
47
- :status => 200,
48
- :headers => {'Content-Type' => 'text/xml; charset=utf-8'},
49
- :body => stub_response)
50
- # soap (dummy)
51
- stub_soap_url = 'https://example.com/test'
52
- stub_response = File.read(File.expand_path('../data/swissindex.xml', __FILE__))
53
- stub_request(:post, stub_soap_url).
54
- with(:headers => {
55
- 'Accept' => '*/*',
56
- 'User-Agent' => 'Ruby'}).
57
- to_return(
58
- :status => 200,
59
- :headers => {'Content-Type' => 'text/xml; chaprset=utf-8'},
60
- :body => stub_response)
39
+ ['Pharma', 'NonPharma'].each do |type|
40
+ # wsdl
41
+ stub_wsdl_url = "https://index.ws.e-mediat.net/Swissindex/#{type}/ws_#{type}_V101.asmx?WSDL"
42
+ stub_response = File.read(File.expand_path("../data/wsdl_#{type.downcase}.xml", __FILE__))
43
+ stub_request(:get, stub_wsdl_url).
44
+ with(:headers => {
45
+ 'Accept' => '*/*',
46
+ 'User-Agent' => 'Ruby'}).
47
+ to_return(
48
+ :status => 200,
49
+ :headers => {'Content-Type' => 'text/xml; charset=utf-8'},
50
+ :body => stub_response)
51
+ # soap (dummy)
52
+ stub_soap_url = 'https://example.com/test'
53
+ stub_response = File.read(File.expand_path("../data/swissindex_#{type.downcase}.xml", __FILE__))
54
+ stub_request(:post, stub_soap_url).
55
+ with(:headers => {
56
+ 'Accept' => '*/*',
57
+ 'User-Agent' => 'Ruby'}).
58
+ to_return(
59
+ :status => 200,
60
+ :headers => {'Content-Type' => 'text/xml; chaprset=utf-8'},
61
+ :body => stub_response)
62
+ end
61
63
  end
62
64
  end
63
65
 
@@ -65,6 +67,8 @@ RSpec.configure do |config|
65
67
  config.treat_symbols_as_metadata_keys_with_true_values = true
66
68
  config.run_all_when_everything_filtered = true
67
69
  config.filter_run :focus
70
+ config.filter_run_excluding :slow
71
+ #config.exclusion_filter = {:slow => true}
68
72
 
69
73
  # Run specs in random order to surface order dependencies. If you find an
70
74
  # order dependency and want to debug it, you can fix the order by providing
metadata CHANGED
@@ -1,48 +1,63 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: oddb2xml
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.6
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
5
  prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 7
10
+ version: 1.0.7
6
11
  platform: ruby
7
- authors:
12
+ authors:
8
13
  - Yasuhiro Asaka, Zeno R.R. Davatz
9
14
  autorequire:
10
15
  bindir: bin
11
16
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2012-11-20 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
15
21
  name: rdoc
16
- requirement: &9947840 !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
17
24
  none: false
18
- requirements:
25
+ requirements:
19
26
  - - ~>
20
- - !ruby/object:Gem::Version
21
- version: '3.10'
27
+ - !ruby/object:Gem::Version
28
+ hash: 19
29
+ segments:
30
+ - 3
31
+ - 10
32
+ version: "3.10"
22
33
  type: :development
23
- prerelease: false
24
- version_requirements: *9947840
25
- - !ruby/object:Gem::Dependency
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
26
36
  name: hoe
27
- requirement: &9947060 !ruby/object:Gem::Requirement
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
28
39
  none: false
29
- requirements:
40
+ requirements:
30
41
  - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '2.13'
42
+ - !ruby/object:Gem::Version
43
+ hash: 25
44
+ segments:
45
+ - 2
46
+ - 13
47
+ version: "2.13"
33
48
  type: :development
34
- prerelease: false
35
- version_requirements: *9947060
36
- description: ''
37
- email:
49
+ version_requirements: *id002
50
+ description: ""
51
+ email:
38
52
  - yasaka@ywesee.com, zdavatz@ywesee.com
39
- executables:
53
+ executables:
40
54
  - oddb2xml
41
55
  extensions: []
42
- extra_rdoc_files:
56
+
57
+ extra_rdoc_files:
43
58
  - History.txt
44
59
  - Manifest.txt
45
- files:
60
+ files:
46
61
  - .gitignore
47
62
  - .rspec
48
63
  - Gemfile
@@ -73,28 +88,37 @@ files:
73
88
  - spec/spec_helper.rb
74
89
  homepage:
75
90
  licenses: []
91
+
76
92
  post_install_message:
77
- rdoc_options:
93
+ rdoc_options:
78
94
  - --main
79
95
  - README.txt
80
- require_paths:
96
+ require_paths:
81
97
  - lib
82
- required_ruby_version: !ruby/object:Gem::Requirement
98
+ required_ruby_version: !ruby/object:Gem::Requirement
83
99
  none: false
84
- requirements:
85
- - - ! '>='
86
- - !ruby/object:Gem::Version
87
- version: '0'
88
- required_rubygems_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 3
104
+ segments:
105
+ - 0
106
+ version: "0"
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
108
  none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ hash: 3
113
+ segments:
114
+ - 0
115
+ version: "0"
94
116
  requirements: []
117
+
95
118
  rubyforge_project: oddb2xml
96
119
  rubygems_version: 1.8.15
97
120
  signing_key:
98
121
  specification_version: 3
99
- summary: ''
122
+ summary: ""
100
123
  test_files: []
124
+