Class: ODDB::Export::Xls::ComparisonDeCh
- Inherits:
-
Object
- Object
- ODDB::Export::Xls::ComparisonDeCh
- Defined in:
- lib/oddb/export/xls.rb
Instance Attribute Summary collapse
-
#backtrace_info ⇒ Object
readonly
Returns the value of attribute backtrace_info.
-
#error_data ⇒ Object
readonly
Returns the value of attribute error_data.
Instance Method Summary collapse
- #adjust_price(price) ⇒ Object
- #collect_cell(local, remote, format = "%s (%s)", &block) ⇒ Object
- #collect_comparables(drb_uri) ⇒ Object
- #currency_rate ⇒ Object
- #export(drb_uri, io) ⇒ Object
- #tax_factor ⇒ Object
- #write_row(worksheet, idx, local, remote) ⇒ Object
- #write_xls(io, data) ⇒ Object
Instance Attribute Details
#backtrace_info ⇒ Object (readonly)
Returns the value of attribute backtrace_info.
15 16 17 |
# File 'lib/oddb/export/xls.rb', line 15 def backtrace_info @backtrace_info end |
#error_data ⇒ Object (readonly)
Returns the value of attribute error_data.
14 15 16 |
# File 'lib/oddb/export/xls.rb', line 14 def error_data @error_data end |
Instance Method Details
#adjust_price(price) ⇒ Object
19 20 21 |
# File 'lib/oddb/export/xls.rb', line 19 def adjust_price(price) price * currency_rate * tax_factor end |
#collect_cell(local, remote, format = "%s (%s)", &block) ⇒ Object
50 51 52 53 54 |
# File 'lib/oddb/export/xls.rb', line 50 def collect_cell(local, remote, format = "%s (%s)", &block) lval = block.call(local) rescue StandardError rval = block.call(remote) rescue StandardError lval == rval ? lval : sprintf(format, lval, rval) end |
#collect_comparables(drb_uri) ⇒ Object
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 |
# File 'lib/oddb/export/xls.rb', line 22 def collect_comparables(drb_uri) data = [] @error_data = [] @backtrace_info = [] DRb::DRbObject.new(nil, drb_uri).remote_each_package { |remote| package = Remote::Drugs::Package.new(drb_uri, remote, 1.0 / currency_rate, tax_factor) begin if(package.price(:public) \ && (comparable = package.local_comparables.select { |pac| pac.price(:public) }.sort_by { |pac| pac.price(:public) }.first)) data.push [comparable, package] end rescue NoMethodError => err # This is a temporary solution for a NoMethodError bug # See the bug http://dev.ywesee.com/wiki.php/Masa/20101020-debug-importChdeXls#DebugChde @error_data.push("http://ch.oddb.org/en/gcc/compare/ean13/" + package.code(:ean).value) @backtrace_info.push("\nhttp://ch.oddb.org/en/gcc/compare/ean13/" + package.code(:ean).value) @backtrace_info.concat err.backtrace end nil # don't return data from the block across drb } data end |
#currency_rate ⇒ Object
55 56 57 |
# File 'lib/oddb/export/xls.rb', line 55 def currency_rate @currency_rate ||= Currency.rate('EUR', 'CHF') end |
#export(drb_uri, io) ⇒ Object
16 17 18 |
# File 'lib/oddb/export/xls.rb', line 16 def export(drb_uri, io) write_xls(io, collect_comparables(drb_uri)) end |
#tax_factor ⇒ Object
58 59 60 |
# File 'lib/oddb/export/xls.rb', line 58 def tax_factor 1.076 / 1.19 end |
#write_row(worksheet, idx, local, remote) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/oddb/export/xls.rb', line 61 def write_row(worksheet, idx, local, remote) comparison = Util::Comparison.new(local, remote) lexf = local.price(:exfactory) rexf = remote.price(:exfactory) data = [ collect_cell(local, remote) { |x| x.name.de || x.product.name.de }, collect_cell(local, remote) { |x| x.comparable_size.to_s }, adjust_price(local.price(:public)).to_s, collect_cell(local, remote) { |x| x.company.name.de }, local.code(:cid).to_s, remote.code(:ean).to_s, collect_cell(local, remote) { |x| x.galenic_forms.first.description.de }, collect_cell(local, remote) { |x| x.active_agents.first.dose.to_s }, collect_cell(local, remote) { |x| x.active_agents.first.substance.name.de }, remote.atc.code, remote.ikscat, remote.sl_entry ? 'SL' : '', sprintf("%+4.2f", adjust_price(comparison.absolute)), sprintf("%+4.2f%%", comparison.difference), sprintf("%4.2f", comparison.factor), (adjust_price(lexf) if lexf).to_s, (adjust_price(rexf) if rexf).to_s, ] if(lexf && rexf) data.push sprintf("%+4.2f", adjust_price(comparison.absolute_exfactory)), sprintf("%+4.2f%%", comparison.difference_exfactory) end worksheet.write idx, 0, data end |
#write_xls(io, data) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/oddb/export/xls.rb', line 94 def write_xls(io, data) workbook = Spreadsheet::Excel.new(io) worksheet = workbook.add_worksheet('Preisvergleich') fmt_title = Spreadsheet::Format.new(:bold => true) workbook.add_format(fmt_title) worksheet.write 0, 0, [ "Name DE (Name CH)", "Pkg Grösse DE (Pkg Grösse CH)", "AVP inkl. Mwst in CHF nach Abzug und Zuschlag", "Hersteller DE (Hersteller CH)", "PZN", "EAN", "Gal Form DE (gal. Form CH)", "Stärke (Schreibweise CH)", "Wirkstoff (Schreibweise CH)", "ATC-Code", "Abgabekategorie CH", "SL Schweiz", "Preisunterschied inkl. Mwst. in CHF", "Preisunterschied in % (normalisiert)", "Packungsäquivalenzfaktor", "FAP DE exkl. MwSt (errechnet)", "FAP CH exkl. MwSt", "Preisunterschied FAP in CHF ", "Preisunterschied FAP in % (normalisiert)", ], fmt_title data.sort_by { |local, remote| local.name.de || local.product.name.de }.each_with_index { |(local, remote), idx| write_row(worksheet, idx.next, local, remote) } workbook.close end |