Module: Oddb2xml::Options

Defined in:
lib/oddb2xml/options.rb

Class Method Summary collapse

Class Method Details

.parse(args = ARGV) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/oddb2xml/options.rb', line 6

def self.parse(args = ARGV)
  if args.is_a?(String)
    args = args.split(" ")
  end

  @opts = Optimist.options(args) do
    version "#{$0} ver.#{Oddb2xml::VERSION}"
    banner <<-EOS
    #{File.expand_path($0)} version #{Oddb2xml::VERSION}
    Usage:
    oddb2xml [option]
      produced files are found under data
    EOS
    opt :append, "Additional target nonpharma", default: false
    opt :artikelstamm, "Create Artikelstamm Version 3 and 5 for Elexis >= 3.1"
    opt :compress_ext, "format F. {tar.gz|zip}", type: :string, default: nil, short: "c"
    opt :extended, "pharma, non-pharma plus prices and non-pharma from zurrose.
                        Products without EAN-Code will also be listed.
                        File oddb_calc.xml will also be generated"
    opt :format, "File format F, default is xml. {xml|dat}
                        If F is given, -o option is ignored.", type: :string, default: "xml"
    opt :include, "Include target option for ean14  for 'dat' format.
                        'xml' format includes always ean14 records.", short: "i"
    opt :increment, "Increment price by x percent. Forces -f dat -p zurrose.
                        create additional field price_resellerpub as
                        price_extfactory incremented by x percent (rounded to the next 0.05 francs)
                        in oddb_article.xml. In generated zurrose_transfer.dat PRPU is set to this price
                        Forces -f dat -p zurrose.", type: :int, default: nil, short: "I"
    opt :fi, "Optional fachinfo output.", short: "o"
    opt :price, "Price source (transfer.dat) from ZurRose", default: nil
    opt :tag_suffix, "XML tag suffix S. Default is none. [A-z0-9]
                        If S is given, it is also used as prefix of filename.", type: :string, short: "t"
    opt :context, "{product|address}. product is default.", default: "product", type: :string, short: "x"
    opt :calc, "create only oddb_calc.xml with GTIN, name and galenic information"

    opt :skip_download, "skips downloading files it the file is already under downloads.
                        Downloaded files are saved under downloads"
    opt :log, "log important actions", short: :none
    opt :use_ra11zip, "Use the ra11.zip (a zipped transfer.dat from Galexis)",
      default: File.exist?("ra11.zip") ? "ra11.zip" : nil, type: :string
  end

  @opts[:percent] = @opts[:increment]
  if @opts[:increment]
    @opts[:nonpharma] = true
    @opts[:price] = :zurrose
  end
  @opts[:ean14] = @opts[:increment]
  @opts.delete(:increment)
  @opts[:nonpharma] = @opts[:append]
  @opts.delete(:append)
  if @opts[:extended]
    @opts[:nonpharma] = true
    @opts[:price] = :zurrose
    @opts[:calc] = true
  end
  if @opts[:artikelstamm]
    @opts[:extended] = true
    @opts[:price] = :zurrose
  end
  @opts[:price] = :zurrose if @opts[:price].is_a?(TrueClass)
  @opts[:price] = @opts[:price].to_sym if @opts[:price]
  @opts[:ean14] = @opts[:include]
  @opts[:format] = @opts[:format].to_sym if @opts[:format]
  @opts.delete(:include)
  @opts.delete(:help)
  @opts.delete(:version)

  @opts[:address] = false
  @opts[:address] = true if /^addr(ess)*$/i.match?(@opts[:context])
  @opts.delete(:context)

  @opts.delete(:price) unless @opts[:price]

  @opts.each { |k, v| @opts.delete(k) if /_given$/.match?(k.to_s) }
end