patinfo2csv 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.0.1 / 23.03.2012
2
+
3
+ * Added 3-bit character patterns
4
+ * updated as pattern
5
+ * added pattern for unexpected string
6
+
1
7
  === 1.0.0 / 22.03.2012
2
8
 
3
9
  * Initial commit for patinfo2csv
data/README.txt CHANGED
@@ -13,13 +13,14 @@ only 4 chapters(de, text) in patinfo.yaml are extracted.
13
13
  * usage
14
14
  * composition
15
15
 
16
- You can specify the pharmacode, see `patinfo2csv --help`
16
+ You can specify the eancode, see `patinfo2csv --help`
17
17
 
18
18
  == Usage
19
19
 
20
20
  $ patinfo2csv --help
21
- Usage: patinfo2csv <input patinfo.yaml> <output patinfo.csv> <input pharmacode.txt>
21
+ Usage: patinfo2csv <input patinfo.yaml> <output patinfo.csv> <input eancode.txt> [-l (de|fr)]
22
22
  -v, --version Show version
23
+ -l, --lang Language option (de|fr) default de
23
24
  -h, --help Print this help message
24
25
 
25
26
  == Requirements
data/bin/patinfo2csv CHANGED
@@ -11,7 +11,7 @@ LANGUAGE = [
11
11
 
12
12
  argv = ARGV.dup
13
13
  opts = Slop.parse! argv, :help => true do
14
- banner "Usage: patinfo2csv <input patinfo.yaml> <output patinfo.csv> <input pharmacode.txt> [-l (de|fr)]"
14
+ banner "Usage: patinfo2csv <input patinfo.yaml> <output patinfo.csv> <input eancode.txt> [-l (de|fr)]"
15
15
  on :v, :version, 'Show version'
16
16
  on :l, :lang, 'Language option (de|fr) default de', :argument => true
17
17
  end
@@ -23,6 +23,15 @@ else
23
23
  lang = "de"
24
24
  end
25
25
 
26
+ root = Pathname.new(__FILE__).realpath.parent.parent
27
+ $:.unshift root.join('lib') if $0 == __FILE__
28
+
29
+ if opts.version? then
30
+ require 'version'
31
+ puts "patinfo2csv " + Patinfo2csv::VERSION + "\n"
32
+ exit
33
+ end
34
+
26
35
  if argv.empty? \
27
36
  or !argv.length.eql? 3 \
28
37
  or !File.exist?(argv[0]) \
@@ -32,14 +41,5 @@ if argv.empty? \
32
41
  exit
33
42
  end
34
43
 
35
- root = Pathname.new(__FILE__).realpath.parent.parent
36
- $:.unshift root.join('lib') if $0 == __FILE__
37
-
38
- if opts.version? then
39
- require 'patinfo2csv/version'
40
- puts "patinfo2csv " + Patinfo2csv::VERSION + "\n"
41
- exit
42
- end
43
-
44
44
  require 'patinfo2csv'
45
45
  Patinfo2csv::CLI.run(argv[0], argv[2], argv[1], lang)
@@ -7,22 +7,23 @@ require 'patinfo2csv'
7
7
  module Patinfo2csv
8
8
  class CLI
9
9
  class << self
10
- # Param:: patinfo.yaml
11
- # Param:: pharmacode.txt
12
- # Param:: patinfo.csv
13
- def run(patinfo, pharmacode, output, lang)
10
+ # Param:: patinfo_yaml patinfo.yaml
11
+ # Param:: code_txt eancode.txt
12
+ # Param:: output_file patinfo.csv
13
+ # Param:: lang (de|fr)
14
+ def run(patinfo_yaml, code_txt, output_file, lang)
14
15
  cv = Patinfo2csv::Converter.new()
15
- cv.lang = lang
16
- cv.patinfo = self.load_yaml(patinfo)
17
- cv.pharmacode = self.parse_txt(pharmacode)
16
+ cv.lang = lang
17
+ cv.patinfos = self.load_yaml(patinfo_yaml)
18
+ cv.codes = self.parse_txt(code_txt)
18
19
  rows = cv.to_csv
19
- self.output_rows(rows, output)
20
- report(rows, cv.pharmacode, lang)
20
+ self.output_rows(rows, output_file)
21
+ report(rows, cv.codes, lang)
21
22
  end
22
- def load_yaml(patinfo)
23
+ def load_yaml(patinfo_yaml)
23
24
  # before yaml loading, replace escaped chars
24
25
  file = ''
25
- File.open(patinfo, "r:ascii:utf-8") { |f|
26
+ File.open(patinfo_yaml, "r:ascii:utf-8") { |f|
26
27
  while line = f.gets
27
28
  ESCAPED_STR_CODE_MAP.each do |code, char|
28
29
  line.gsub!(code, char)
@@ -33,18 +34,18 @@ module Patinfo2csv
33
34
  fh = StringIO.new file
34
35
  YAML.load_documents(fh) # utf-8
35
36
  end
36
- def parse_txt(pharmacode)
37
+ def parse_txt(code_txt)
37
38
  codes = []
38
- File.open(pharmacode, "r:utf-8") do |input|
39
+ File.open(code_txt, "r:utf-8") do |input|
39
40
  while line=input.gets
40
41
  codes << line.gsub(/[^\d]/, '').chomp
41
42
  end
42
43
  end
43
44
  codes
44
45
  end
45
- def output_rows(rows, output)
46
+ def output_rows(rows, output_file)
46
47
  return unless rows
47
- open(output, "w:utf-8") do |out|
48
+ open(output_file, "w:utf-8") do |out|
48
49
  rows.each do |row|
49
50
  out.print row, "\n"
50
51
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Patinfo2csv
5
5
  class Converter
6
- attr_accessor :patinfo, :pharmacode, :lang
6
+ attr_accessor :patinfos, :codes, :lang
7
7
  attr_reader :rows
8
8
  CHAPTERS = [
9
9
  :effects,
@@ -14,32 +14,36 @@ module Patinfo2csv
14
14
  ]
15
15
  DELIMITER = ';'
16
16
  def initialize
17
- @lang = "de"
18
- @patinfo = []
19
- @pharmacode = []
20
- @rows = []
17
+ @lang = "de"
18
+ @patinfos = []
19
+ @codes = []
20
+ @rows = []
21
21
  end
22
22
  def to_csv
23
23
  data = []
24
- @patinfo.each_with_index do |row, index|
24
+ @patinfos.each_with_index do |row, index|
25
25
  target = []
26
26
  next if row['article_codes'].nil?
27
- row['article_codes'].each do |code|
28
- if @pharmacode.include?(code[:article_pcode])
29
- target << code[:article_pcode]
30
- @pharmacode.delete(code[:article_pcode])
27
+ row['article_codes'].each do |article|
28
+ if @codes.include?(article[:article_ean13]) # EAN
29
+ target << article[:article_ean13]
30
+ @codes.delete(article[:article_ean13])
31
+ #elsif @code.include?(code[:article_pcode]) # Pharmacode
32
+ # target << code[:article_pcode]
33
+ # @code.delete(code[:article_pcode])
31
34
  end
32
35
  end
33
36
  next if target.empty?
34
37
  chapters = extract_chapters(row)
35
38
  next if chapters.empty?
36
- target.each do |pcode|
37
- @rows << [%Q!"#{pcode}"!, chapters].flatten.join(DELIMITER)
39
+ target.each do |code|
40
+ @rows << [%Q!"#{code}"!, chapters].flatten.join(DELIMITER)
38
41
  end
39
42
  end
40
43
  unless @rows.empty? #header
41
44
  @rows.unshift([
42
- "Pharmacode",
45
+ "EAN",
46
+ #"Pharmacode",
43
47
  "Effects",
44
48
  "Contra Indication",
45
49
  "Pregnancy",
data/lib/patinfo2csv.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
 
4
- require 'patinfo2csv/version'
4
+ require 'version'
5
5
  require 'patinfo2csv/cli'
6
6
  require 'patinfo2csv/converter'
7
7
 
@@ -10,82 +10,107 @@ module Patinfo2csv
10
10
  # escaped backslash and utf-8 code map
11
11
  # for patinfo.yaml(ASII)
12
12
  ESCAPED_STR_CODE_MAP = {
13
- "\\x24" => "$",
14
- "\\x25" => "%",
15
- "\\x26" => "&",
16
- "\\x2D" => "-",
17
- "\\x5F" => "_",
18
- "\\xC2\\xA0" => " ",
19
- "\\xC2\\xAB" => "«",
20
- "\\xC2\\xBB" => "»",
21
- "\\xC2\\xAE" => "®",
22
- "\\xC2\\xA9" => "©",
23
- "\\xC2\\xB5" => "µ",
24
- "\\xC2\\xBD" => "½",
25
- "\\xC2\\xBC" => "¼",
26
- "\\xC2\\xBE" => "¾",
27
- "\\xC3\\x82" => "Â",
28
- "\\xC3\\x83" => "Ã",
29
- "\\xC3\\x84" => "Ä",
30
- "\\xC3\\x85" => "Å",
31
- "\\xC3\\x86" => "Æ",
32
- "\\xC3\\x87" => "Ç",
33
- "\\xC3\\x88" => "È",
34
- "\\xC3\\x89" => "É",
35
- "\\xC3\\x8A" => "Ê",
36
- "\\xC3\\x8B" => "Ë",
37
- "\\xC3\\x8C" => "Ì",
38
- "\\xC3\\x8D" => "Í",
39
- "\\xC3\\x8E" => "Î",
40
- "\\xC3\\x8F" => "Ï",
41
- "\\xC3\\x90" => "Ð",
42
- "\\xC3\\x91" => "Ñ",
43
- "\\xC3\\x92" => "Ò",
44
- "\\xC3\\x93" => "Ó",
45
- "\\xC3\\x94" => "Ô",
46
- "\\xC3\\x95" => "Õ",
47
- "\\xC3\\x96" => "Ö",
48
- "\\xC3\\x97" => "×",
49
- "\\xC3\\x98" => "Ø",
50
- "\\xC3\\x99" => "Ù",
51
- "\\xC3\\x9A" => "Ú",
52
- "\\xC3\\x9B" => "Û",
53
- "\\xC3\\x9C" => "Ü",
54
- "\\xC3\\x9D" => "Ý",
55
- "\\xC3\\x9E" => "Þ",
56
- "\\xC3\\x9F" => "ß",
57
- "\\xC3\\xA0" => "à",
58
- "\\xC3\\xA1" => "á",
59
- "\\xC3\\xA2" => "â",
60
- "\\xC3\\xA3" => "ã",
61
- "\\xC3\\xA4" => "ä",
62
- "\\xC3\\xA5" => "å",
63
- "\\xC3\\xA6" => "æ",
64
- "\\xC3\\xA7" => "ç",
65
- "\\xC3\\xA8" => "è",
66
- "\\xC3\\xA9" => "é",
67
- "\\xC3\\xAA" => "ê",
68
- "\\xC3\\xAB" => "ë",
69
- "\\xC3\\xAC" => "ì",
70
- "\\xC3\\xAD" => "í",
71
- "\\xC3\\xAE" => "î",
72
- "\\xC3\\xAF" => "ï",
73
- "\\xC3\\xB0" => "ð",
74
- "\\xC3\\xB1" => "ñ",
75
- "\\xC3\\xB2" => "ò",
76
- "\\xC3\\xB3" => "ó",
77
- "\\xC3\\xB4" => "ô",
78
- "\\xC3\\xB5" => "õ",
79
- "\\xC3\\xB6" => "ö",
80
- "\\xC3\\xB7" => "÷",
81
- "\\xC3\\xB8" => "ø",
82
- "\\xC3\\xB9" => "ù",
83
- "\\xC3\\xBA" => "ú",
84
- "\\xC3\\xBB" => "û",
85
- "\\xC3\\xBC" => "ü",
86
- "\\xC3\\xBD" => "ý",
87
- "\\xC3\\xBE" => "þ",
88
- "\\xC3\\xBF" => "ÿ",
89
- "\\xE2\\x80\\x93" => "",
13
+ /\\x24/ => "$",
14
+ /\\x25/ => "%",
15
+ /\\x26/ => "&",
16
+ /\\x2D/ => "-",
17
+ /\\x5F/ => "_",
18
+ /\\xC2\\xA0/ => " ",
19
+ /\\xC2\\xAB/ => "«",
20
+ /\\xC2\\xBB/ => "»",
21
+ /\\xC2\\xAE/ => "®",
22
+ /\\xC2\\xA9/ => "©",
23
+ /\\xC2\\xB5/ => "µ",
24
+ /\\xC2\\xBD/ => "½",
25
+ /\\xC2\\xBC/ => "¼",
26
+ /\\xC2\\xBE/ => "¾",
27
+ /\\xC2\\x[A-z0-9]{2}/ => "",
28
+ /\\xC3\\x82/ => "Â",
29
+ /\\xC3\\x83/ => "Ã",
30
+ /\\xC3\\x84/ => "Ä",
31
+ /\\xC3\\x85/ => "Å",
32
+ /\\xC3\\x86/ => "Æ",
33
+ /\\xC3\\x87/ => "Ç",
34
+ /\\xC3\\x88/ => "È",
35
+ /\\xC3\\x89/ => "É",
36
+ /\\xC3\\x8A/ => "Ê",
37
+ /\\xC3\\x8B/ => "Ë",
38
+ /\\xC3\\x8C/ => "Ì",
39
+ /\\xC3\\x8D/ => "Í",
40
+ /\\xC3\\x8E/ => "Î",
41
+ /\\xC3\\x8F/ => "Ï",
42
+ /\\xC3\\x90/ => "Ð",
43
+ /\\xC3\\x91/ => "Ñ",
44
+ /\\xC3\\x92/ => "Ò",
45
+ /\\xC3\\x93/ => "Ó",
46
+ /\\xC3\\x94/ => "Ô",
47
+ /\\xC3\\x95/ => "Õ",
48
+ /\\xC3\\x96/ => "Ö",
49
+ /\\xC3\\x97/ => "×",
50
+ /\\xC3\\x98/ => "Ø",
51
+ /\\xC3\\x99/ => "Ù",
52
+ /\\xC3\\x9A/ => "Ú",
53
+ /\\xC3\\x9B/ => "Û",
54
+ /\\xC3\\x9C/ => "Ü",
55
+ /\\xC3\\x9D/ => "Ý",
56
+ /\\xC3\\x9E/ => "Þ",
57
+ /\\xC3\\x9F/ => "ß",
58
+ /\\xC3\\xA0/ => "à",
59
+ /\\xC3\\xA1/ => "á",
60
+ /\\xC3\\xA2/ => "â",
61
+ /\\xC3\\xA3/ => "ã",
62
+ /\\xC3\\xA4/ => "ä",
63
+ /\\xC3\\xA5/ => "å",
64
+ /\\xC3\\xA6/ => "æ",
65
+ /\\xC3\\xA7/ => "ç",
66
+ /\\xC3\\xA8/ => "è",
67
+ /\\xC3\\xA9/ => "é",
68
+ /\\xC3\\xAA/ => "ê",
69
+ /\\xC3\\xAB/ => "ë",
70
+ /\\xC3\\xAC/ => "ì",
71
+ /\\xC3\\xAD/ => "í",
72
+ /\\xC3\\xAE/ => "î",
73
+ /\\xC3\\xAF/ => "ï",
74
+ /\\xC3\\xB0/ => "ð",
75
+ /\\xC3\\xB1/ => "ñ",
76
+ /\\xC3\\xB2/ => "ò",
77
+ /\\xC3\\xB3/ => "ó",
78
+ /\\xC3\\xB4/ => "ô",
79
+ /\\xC3\\xB5/ => "õ",
80
+ /\\xC3\\xB6/ => "ö",
81
+ /\\xC3\\xB7/ => "÷",
82
+ /\\xC3\\xB8/ => "ø",
83
+ /\\xC3\\xB9/ => "ù",
84
+ /\\xC3\\xBA/ => "ú",
85
+ /\\xC3\\xBB/ => "û",
86
+ /\\xC3\\xBC/ => "ü",
87
+ /\\xC3\\xBD/ => "ý",
88
+ /\\xC3\\xBE/ => "þ",
89
+ /\\xC3\\xBF/ => "ÿ",
90
+ /\\xC3\\x[A-z0-9]{2}/ => "",
91
+ /\\xE2\\x80\\x90/ => "‐",
92
+ /\\xE2\\x80\\x91/ => "‑",
93
+ /\\xE2\\x80\\x92/ => "‒",
94
+ /\\xE2\\x80\\x93/ => "–",
95
+ /\\xE2\\x80\\x94/ => "—",
96
+ /\\xE2\\x80\\x95/ => "―",
97
+ /\\xE2\\x80\\x98/ => "‘",
98
+ /\\xE2\\x80\\x99/ => "’",
99
+ /\\xE2\\x80\\x9A/ => "‚",
100
+ /\\xE2\\x80\\x9B/ => "‛",
101
+ /\\xE2\\x80\\x9C/ => "“",
102
+ /\\xE2\\x80\\x9D/ => "”",
103
+ /\\xE2\\x80\\x9E/ => "„",
104
+ /\\xE2\\x80\\x9F/ => "‟",
105
+ /\\xE2\\x80\\xA6/ => "…",
106
+ /\\xE2\\x80\\xB0/ => "‰",
107
+ /\\xE2\\x80\\xB1/ => "‱",
108
+ /\\xE2\\x80\\xB2/ => "′",
109
+ /\\xE2\\x80\\xB3/ => "″",
110
+ /\\xE2\\x80\\xB4/ => "‴",
111
+ /\\xE2\\x80\\xB5/ => "‵",
112
+ /\\xE2\\x80\\xB6/ => "‶",
113
+ /\\xE2\\x80\\xB7/ => "‷",
114
+ /\\xE2\\x[A-z0-9]{2}\\x[A-z0-9]{2}/ => "",
90
115
  }
91
116
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Patinfo2csv
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patinfo2csv
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-22 00:00:00.000000000 Z
12
+ date: 2012-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
16
- requirement: &25013040 !ruby/object:Gem::Requirement
16
+ requirement: &10742100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.10'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *25013040
24
+ version_requirements: *10742100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hoe
27
- requirement: &25012580 !ruby/object:Gem::Requirement
27
+ requirement: &10741680 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '2.13'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *25012580
35
+ version_requirements: *10741680
36
36
  description: ! 'Patinfo2csv extracts and converts patinfo.yaml to patinfo.csv;
37
37
 
38
38
  only 4 chapters(de, text) in patinfo.yaml are extracted.
@@ -49,7 +49,7 @@ description: ! 'Patinfo2csv extracts and converts patinfo.yaml to patinfo.csv;
49
49
  * composition
50
50
 
51
51
 
52
- You can specify the pharmacode, see `patinfo2csv --help`'
52
+ You can specify the eancode, see `patinfo2csv --help`'
53
53
  email:
54
54
  - yasaka@ywesee.com, zdavatz@ywesee.com
55
55
  executables: