ebps 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,34 @@
1
+ = Using and setting up ebps on Linux
2
+
3
+ Place the config files in
4
+
5
+ /etc/ebps/meddrugs.ch_de_firefox.yml
6
+
7
+ The ebook scripts go here
8
+
9
+ /var/ebps/bin/meddrugs.ch_de_firefox
10
+
11
+ Every config file corresponds to one ebook-job. This is important.
12
+
13
+ The covers, CSS and more go here:
14
+
15
+ /var/ebps/data/
16
+
17
+ in the data directory you will see
18
+
19
+ books (after the job finishes the book will be here)
20
+ covers (book cover and last page)
21
+ css (Cascading Style Sheet for the style of the book)
22
+ yaml (Original-Source yaml Fachinfo File)
23
+
24
+ The decorators will be here
25
+
26
+ /var/ebps/bin/decorators
27
+
28
+ so that would be
29
+
30
+ just_medical_de.rb
31
+ just_medical_fr.rb
32
+
33
+ The Decorators enable you to do more fun stuff in the Ebook, like use links to
34
+ drug-price comparisons or link to specific product pages of any given drug, etc.
@@ -1,3 +1,11 @@
1
+ === 1.0.4 / 18.06.2013
2
+
3
+ * Add error handling for patinfo
4
+
5
+ === 1.0.3 / 30.03.2012
6
+
7
+ * Updated just_medical decorators to search drugs with iksnr
8
+
1
9
  === 1.0.2 / 17.12.2010
2
10
 
3
11
  * Decorators now work with links in the ebooks.
@@ -1,11 +1,16 @@
1
+ Guide.txt
1
2
  History.txt
2
- InstalledFiles
3
3
  LICENSE.txt
4
4
  Manifest.txt
5
5
  README.txt
6
6
  Rakefile
7
- SetupConfig
8
7
  bin/ebps
8
+ data/css/emediat.css
9
+ data/css/oddb.css
10
+ decorators/ch_oddb_de.rb
11
+ decorators/ch_oddb_fr.rb
12
+ decorators/just_medical_de.rb
13
+ decorators/just_medical_fr.rb
9
14
  example/config.yml
10
15
  example/converter_for_firefox.rb
11
16
  example/data.yml
@@ -36,6 +41,7 @@ lib/ebps/text/picture.rb
36
41
  lib/ebps/text/table.rb
37
42
  lib/ebps/util/mail.rb
38
43
  lib/ebps/util/smtp_tls.rb
44
+ setup.rb
39
45
  spec/conversion/data/DF_15164_1_3.gif
40
46
  spec/conversion/data/DF_15164_2_3.gif
41
47
  spec/conversion/data/appendix.png
@@ -51,6 +57,7 @@ spec/conversion/fachinfo_xml_spec.rb
51
57
  spec/conversion/fachinfo_yaml_spec.rb
52
58
  spec/conversion/mobi_pocket_spec.rb
53
59
  spec/conversion/oebps_spec.rb
60
+ spec/suite.rb
54
61
  spec/text/chapter_spec.rb
55
62
  spec/text/document_spec.rb
56
63
  spec/text/paragraph_spec.rb
data/Rakefile CHANGED
@@ -4,25 +4,15 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
 
6
6
  # Hoe.plugin :compiler
7
- # Hoe.plugin :cucumberfeatures
8
7
  # Hoe.plugin :gem_prelude_sucks
9
8
  # Hoe.plugin :inline
10
9
  # Hoe.plugin :inline
11
- # Hoe.plugin :manifest
12
- # Hoe.plugin :newgem
10
+ # Hoe.plugin :minitest
13
11
  # Hoe.plugin :racc
14
12
  # Hoe.plugin :rubyforge
15
- # Hoe.plugin :rubyforge
16
- # Hoe.plugin :website
17
13
 
18
14
  Hoe.spec 'ebps' do
19
- # HEY! If you fill these out in ~/.hoe_template/Rakefile.erb then
20
- # you'll never have to touch them again!
21
- # (delete this comment too, of course)
22
15
 
23
- developer('Masaomi Hatakeyama, Zeno R.R. Davatz', 'mhatakeyama@ywesee.com, zdavatz@ywesee.com')
16
+ developer('Yasuhiro Asaka, Zeno R.R. Davatz', 'yasaka@ywesee.com, zdavatz@ywesee.com')
24
17
 
25
- # self.rubyforge_name = 'ebpsx' # if different than 'ebps'
26
18
  end
27
-
28
- # vim: syntax=ruby
data/bin/ebps CHANGED
@@ -1,4 +1,6 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/bin/env ruby19
2
+ # encoding: utf-8
3
+ # EBPS -- ebps -- 30.03.2012 -- yasaka@ywesee.com
2
4
 
3
5
  log = []
4
6
 
@@ -12,7 +14,7 @@ particularly in the handling of multibyte characters.
12
14
  warn warning
13
15
  end
14
16
 
15
- $: << File.expand_path('../lib', File.dirname(__FILE__))
17
+ $:.unshift File.expand_path('../lib', File.dirname(__FILE__)) if $0 == __FILE__
16
18
 
17
19
  require 'ebps'
18
20
  require 'ebps/util/mail'
@@ -0,0 +1,19 @@
1
+ .ebps {
2
+ display: block;
3
+ text-indent: 0;
4
+ }
5
+ h3 {
6
+ font-size: larger;
7
+ }
8
+ h4 {
9
+ font-weight: normal;
10
+ font-style: italic;
11
+ }
12
+ table.ebps {
13
+ border-collapse: collapse;
14
+ }
15
+ /*
16
+ table.ebps td {
17
+ border: 1px solid #999;
18
+ }
19
+ */
@@ -0,0 +1,18 @@
1
+ .ebps {
2
+ display: block;
3
+ text-indent: 0;
4
+ }
5
+ h3 {
6
+ font-size: larger;
7
+ }
8
+ h4 {
9
+ font-weight: normal;
10
+ font-style: italic;
11
+ }
12
+ table.ebps {
13
+ border-collapse: collapse;
14
+ }
15
+ table.ebps td {
16
+ padding: 5px 3px;
17
+ border: 1px solid #999;
18
+ }
@@ -0,0 +1,20 @@
1
+ module EBPS
2
+ module Decorator
3
+ module ChOddb
4
+ def self.decorate model
5
+ if codes = model.metadata['article_codes']
6
+ size_ean13s = codes.collect do |hash| [hash[:article_size], hash[:article_dose], hash[:article_ean13]] end.compact
7
+ unless size_ean13s.empty?
8
+ chapter = Text::Chapter.new
9
+ chapter.heading << 'Preisvergleich'
10
+ size_ean13s.each do |size, dose, ean13|
11
+ href = "http://ch.oddb.org/de/gcc/compare/ean13/#{ean13}"
12
+ chapter.add_paragraph Text::LinkedParagraph.new(href, model.title + " " + size.to_s + " " + dose.to_s)
13
+ end
14
+ model.add_chapter chapter
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ module EBPS
2
+ module Decorator
3
+ module ChOddb
4
+ def self.decorate model
5
+ if codes = model.metadata['article_codes']
6
+ size_ean13s = codes.collect do |hash| [hash[:article_size], hash[:article_ean13]] end.compact
7
+ unless size_ean13s.empty?
8
+ chapter = Text::Chapter.new
9
+ chapter.heading << 'Comparaison des prix'
10
+ size_ean13s.each do |size, ean13|
11
+ href = "http://ch.oddb.org/fr/gcc/compare/ean13/#{ean13}"
12
+ chapter.add_paragraph Text::LinkedParagraph.new(href, model.title + " " + size.to_s + " " + ean13.to_s)
13
+ end
14
+ model.add_chapter chapter
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ module EBPS
3
+ module Decorator
4
+ module JustMedical
5
+ def self.decorate model
6
+ model.chapters.each_with_index do |chap, i|
7
+ if chap.heading =~ /Zulassungsinhaberin/
8
+ if chap.paragraphs.first.to_s =~ /AstraZeneca AG/
9
+ table = Text::Table.new
10
+ table.rows[0][0] = Text::LinkedParagraph.new('http://www.astrazeneca.ch/', 'AstraZeneca AG')
11
+ table.rows[0] << Text::Paragraph.new(chap.paragraphs.first.to_s.gsub(/AstraZeneca AG/,''))
12
+ chap.paragraphs[0] = table
13
+ end
14
+ end
15
+ end
16
+
17
+ title = if match = model.title.match(/([\w\s]+)/)
18
+ match[1]
19
+ end
20
+ if codes = model.metadata['article_codes']
21
+ size_ean13s = codes.collect do |hash| [hash[:article_size], hash[:article_dose], hash[:article_ean13]] end.compact
22
+ unless size_ean13s.empty?
23
+ chapter = Text::Chapter.new
24
+ if $0 =~ /meddrugs\.ch_de_patinfo/
25
+ chapter.heading << 'Preisvergleich'
26
+ size_ean13s.each do |size, dose, ean13|
27
+ href = "http://www.med-drugs.ch/index.cfm?&newlang=de&spr=de?&content=meddrugs&oddbparam=/compare/ean13/#{ean13.to_s}"
28
+ chapter.add_paragraph Text::LinkedParagraph.new(href, model.title + " " + size.to_s + " " + dose.to_s)
29
+ end
30
+ else
31
+ chapter.heading << 'Stammdaten'
32
+ size_ean13s.each do |size, dose, ean13|
33
+ reg = ean13[4,5]
34
+ href = if reg
35
+ "http://www.med-drugs.ch/index.cfm?&newlang=de&spr=de?&content=meddrugs&oddbparam=/search/zone/drugs/search_query/#{reg.to_s}/search_type/st_oddb#best_result"
36
+ else
37
+ "http://www.med-drugs.ch"
38
+ end
39
+ chapter.add_paragraph Text::LinkedParagraph.new(href, model.title + " " + size.to_s + " " + dose.to_s)
40
+ end
41
+ end
42
+ model.add_chapter chapter
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ module EBPS
3
+ module Decorator
4
+ module JustMedical
5
+ def self.decorate model
6
+ model.chapters.each_with_index do |chap, i|
7
+ if chap.heading =~ /Titulaire de .+autorisation/
8
+ if chap.paragraphs.first.to_s =~ /AstraZeneca AG/
9
+ table = Text::Table.new
10
+ table.rows[0][0] = Text::LinkedParagraph.new('http://www.astrazeneca.ch/?user_locale=fr', 'AstraZeneca AG')
11
+ table.rows[0] << Text::Paragraph.new(chap.paragraphs.first.to_s.gsub(/AstraZeneca AG/,''))
12
+ chap.paragraphs[0] = table
13
+ end
14
+ end
15
+ end
16
+
17
+ title = if match = model.title.match(/([\w\s]+)/)
18
+ match[1]
19
+ end
20
+ if codes = model.metadata['article_codes']
21
+ size_ean13s = codes.collect do |hash| [hash[:article_size], hash[:article_dose], hash[:article_ean13]] end.compact
22
+ unless size_ean13s.empty?
23
+ chapter = Text::Chapter.new
24
+ if $0 =~ /meddrugs\.ch_fr_patinfo/
25
+ chapter.heading << 'Comparaison des prix'
26
+ size_ean13s.each do |size, dose, ean13|
27
+ href = "http://www.med-drugs.ch/index.cfm?&newlang=fr&spr=fr?&content=meddrugs&oddbparam=/compare/ean13/#{ean13.to_s}"
28
+ chapter.add_paragraph Text::LinkedParagraph.new(href, model.title + " " + size.to_s + " " + dose.to_s)
29
+ end
30
+ else
31
+ chapter.heading << 'Base de données'
32
+ size_ean13s.each do |size, dose, ean13|
33
+ reg = ean13[4,5]
34
+ href = if reg
35
+ "http://www.med-drugs.ch/index.cfm?&newlang=fr&spr=fr?&content=meddrugs&oddbparam=/search/zone/drugs/search_query/#{reg.to_s}/search_type/st_oddb#best_result"
36
+ else
37
+ "http://www.med-drugs.ch"
38
+ end
39
+ chapter.add_paragraph Text::LinkedParagraph.new(href, model.title + " " + size.to_s + " " + dose.to_s)
40
+ end
41
+ end
42
+ model.add_chapter chapter
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,5 +1,5 @@
1
1
  require 'ebps/config'
2
2
 
3
3
  class Ebps
4
- VERSION = '1.0.2'
4
+ VERSION = '1.0.4'
5
5
  end
@@ -1,3 +1,8 @@
1
+ #! /usr/bin/env ruby19
2
+ # encoding: utf-8
3
+ # EBPS::Config -- ebps -- 27.09.2011 -- mhatakeyama@ywesee.com
4
+ # EBPS::Config -- ebps -- 08.07.2010 -- hwyss@ywesee.com
5
+
1
6
  require 'rclconf'
2
7
 
3
8
  module EBPS
@@ -31,6 +36,7 @@ module EBPS
31
36
  'link_drug_brand_name' => false,
32
37
  'max_depth' => 3,
33
38
  'name' => 'ebps',
39
+ 'photos' => '',
34
40
  'preprocess' => {},
35
41
  'postprocess' => {},
36
42
  'report_from' => 'EBPS <ebps@ywesee.com>',
@@ -1,5 +1,11 @@
1
+ # encoding: utf-8
2
+ # EBPS::Conversion:DeFachinfoYaml -- ebps -- 06.08.2012 -- yasaka@ywesee.com
3
+
1
4
  require 'ebps/text/document'
2
5
  require 'yaml'
6
+ if defined? YAML::ENGINE
7
+ YAML::ENGINE.yamler = 'syck'
8
+ end
3
9
 
4
10
  module EBPS
5
11
  YAML.add_domain_type 'de.oddb.org,2007',
@@ -1,3 +1,8 @@
1
+ # /usr/bin/env ruby19
2
+ # encoding: utf-8
3
+ # EBPS::Conversion::FachinfoXml::StreamListener -- ebps -- 27.09.2011 -- mhatakeyama@ywesee.com
4
+ # EBPS::Conversion::FachinfoXml::StreamListener -- ebps -- 12.03.2010 -- hwyss@ywesee.com
5
+
1
6
  require 'ebps/config'
2
7
  require 'ebps/text/document'
3
8
  require 'open-uri'
@@ -18,6 +23,45 @@ module EBPS
18
23
  def end_fi
19
24
  @current_document = nil
20
25
  end
26
+ def end_monid
27
+ dir = File.join(EBPS.config.photos, @current_target.to_s)
28
+ file_list = Dir.glob(File.join(dir, "*.jpg")).to_a.sort
29
+ unless file_list.empty?
30
+ @current_chapter.heading << (EBPS.config.language == 'de' ? 'Fotos' : 'Photos')
31
+ @current_target = Text::Table.new
32
+ file_list.each_with_index do |file, i|
33
+ @current_target.next_row! if i > 0
34
+
35
+ # picture (right)
36
+ picture = Text::Picture.new
37
+ picture << File.read(file)
38
+ #@current_target.rows.last << picture
39
+ @current_target.rows[i][0] = picture
40
+
41
+ # picture name (left)
42
+ @current_target.next_cell!
43
+ filename = File.basename(file).gsub(/\.jpg/,'').gsub(/^\d+_/,'')
44
+ pic_number = if match = File.basename(file).match(/^(\d+)_/)
45
+ match[1]
46
+ end
47
+ url = "https://pictures.e-mediat.net/WV_GetPictures/#{pic_number}_PIF_F.jpg"
48
+ link = Text::LinkedParagraph.new(url, filename)
49
+ #@current_target << filename
50
+ @current_target.rows[i][1] = link
51
+ end
52
+ @current_chapter.add_paragraph(@current_target)
53
+ end
54
+
55
+ @current_target = nil
56
+ @current_chapter = nil
57
+ end
58
+ def start_monid attrs
59
+ @current_chapter = Text::Chapter.new
60
+ @current_document.add_chapter @current_chapter
61
+ @current_target = Text::Paragraph.new
62
+ #@current_chapter.heading << 'Fotos'
63
+ @current_target
64
+ end
21
65
  def end_i
22
66
  @stack.delete 'i'
23
67
  if @current_target.respond_to?(:set_format)
@@ -1,5 +1,12 @@
1
+ #! /usr/bin/env ruby19
2
+ # encoding: utf-8
3
+ # EBPS::Conversion:FachinfoYaml -- ebps -- 08.09.2013 -- yasaka@ywesee.com
4
+
1
5
  require 'ebps/text/document'
2
6
  require 'yaml'
7
+ if defined? YAML::ENGINE
8
+ YAML::ENGINE.yamler = 'syck'
9
+ end
3
10
 
4
11
  module EBPS
5
12
  YAML.add_domain_type 'oddb.org,2003', 'ODDB::Fachinfo' do |type, val|
@@ -10,7 +17,7 @@ module EBPS
10
17
  rescue NoMethodError => err
11
18
  comment = "Probably '#{EBPS.config.language}' data is missing in the following data:\n"
12
19
  err.message << "\n\n" << comment << val.to_a.to_s << "\n"
13
- raise err
20
+ #raise err
14
21
  end
15
22
  doc
16
23
  end
@@ -50,7 +57,9 @@ module EBPS
50
57
  end
51
58
  YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::Paragraph' do |type, val|
52
59
  par = Text::Paragraph.new
53
- par << val['text']
60
+ # TODO
61
+ # remove gsub, after fix escaped character problem in fachinfo.yaml of oddb
62
+ par << val['text'].gsub(/\u001F/, '')
54
63
  Conversion::FachinfoYaml.encode par.text
55
64
  par.formats.replace val['formats']
56
65
  if val['preformatted']
@@ -61,16 +70,15 @@ module EBPS
61
70
  par
62
71
  end
63
72
  YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::ImageLink' do |type, val|
73
+ picture = nil
64
74
  src = File.join EBPS.config.image_prefix, val['src']
65
- file = File.basename src
66
- handle = nil
67
75
  begin
68
76
  handle = open src
69
77
  picture = Text::Picture.new
70
78
  picture << handle.read
71
- picture
72
79
  rescue
73
80
  end
81
+ picture
74
82
  end
75
83
  YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::Format' do |type, val|
76
84
  fmt = Text::Format.new
@@ -79,6 +87,32 @@ module EBPS
79
87
  fmt.end = val['end']
80
88
  fmt
81
89
  end
90
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::Table' do |type, val|
91
+ table = Text::Table.new
92
+ table.rows.replace val['rows']
93
+ table
94
+ end
95
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::Cell' do |type, val|
96
+ cell = Text::Cell.new
97
+ cell << val['text']
98
+ Conversion::FachinfoYaml.encode cell.text
99
+ cell.formats.replace(val['formats']) if val['formats']
100
+ if val['preformatted']
101
+ cell.formats.each do |fmt|
102
+ fmt.values << 'pre'
103
+ end
104
+ end
105
+ cell
106
+ end
107
+ YAML.add_domain_type 'oddb.org,2003', 'ODDB::Text::MultiCell' do |type, val|
108
+ cell = Text::MultiCell.new
109
+ cell << val['text']
110
+ cell.col_span = val['col_span']
111
+ cell.row_span = val['row_span']
112
+ cell.contents = val['contents']
113
+ Conversion::FachinfoYaml.encode cell.text
114
+ cell
115
+ end
82
116
  YAML.add_domain_type 'oddb.org,2003', 'ODDB::SimpleLanguage::Descriptions' do |type, val|
83
117
  val
84
118
  end
@@ -105,6 +139,9 @@ module EBPS
105
139
  doc
106
140
  end
107
141
  def self.encode txt
142
+ if !txt.is_a?(String) and txt.respond_to?(:to_s)
143
+ txt = txt.to_s
144
+ end
108
145
  txt.force_encoding 'UTF-8'
109
146
  txt
110
147
  end