Class: ODDB::Export::Csv::Packages
- Inherits:
-
Object
- Object
- ODDB::Export::Csv::Packages
- Defined in:
- lib/oddb/export/csv.rb
Class Method Summary collapse
- .active_agents(package, lang) ⇒ Object
- .atc_line(atc, language) ⇒ Object
- .ddd_prices(package, language) ⇒ Object
- .export(packages, components, language = :de) ⇒ Object
- .package_line(package, components, language) ⇒ Object
- .partition(packages) ⇒ Object
- .price_exfactory(package, lang) ⇒ Object
- .price_festbetrag(package, lang) ⇒ Object
- .price_public(package, lang) ⇒ Object
- .product(package, language) ⇒ Object
- .pzn(package, lang) ⇒ Object
- .size(package, language) ⇒ Object
Class Method Details
.active_agents(package, lang) ⇒ Object
32 33 34 |
# File 'lib/oddb/export/csv.rb', line 32 def self.active_agents(package, lang) package.active_agents.join('|') end |
.atc_line(atc, language) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/oddb/export/csv.rb', line 21 def self.atc_line(atc, language) if atc result = [atc.code] if name = atc.name result.push name.send(language) end result else ['ATC-Code nicht bekannt'] end end |
.ddd_prices(package, language) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/oddb/export/csv.rb', line 35 def self.ddd_prices(package, language) ddds = [] package.ddds.each_with_index { |ddd, idx| ddds.push sprintf("%s (%s)", package.dose_price(ddd.dose), ddd.administration) } ddds.join '|' end |
.export(packages, components, language = :de) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/oddb/export/csv.rb', line 10 def self.export(packages, components, language = :de) atcs = partition packages CSV.generate { |csv| atcs.each { |list| csv << atc_line(list.atc, language) list.each { |pac| csv << package_line(pac, components, language) } } } end |
.package_line(package, components, language) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/oddb/export/csv.rb', line 43 def self.package_line(package, components, language) components.collect { |key| value = if respond_to?(key) self.send key, package, language elsif package.respond_to?(key) package.send key end case value when Util::Multilingual value.send language else value end } end |
.partition(packages) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/oddb/export/csv.rb', line 58 def self.partition(packages) atcs = {} packages.each { |package| code = (atc = package.atc) ? atc.code : 'X' (atcs[code] ||= Util::AnnotatedList.new(:atc => atc)).push(package) } atcs.sort.collect { |code, packages| packages } end |
.price_exfactory(package, lang) ⇒ Object
68 69 70 |
# File 'lib/oddb/export/csv.rb', line 68 def self.price_exfactory(package, lang) package.price(:exfactory) end |
.price_festbetrag(package, lang) ⇒ Object
71 72 73 |
# File 'lib/oddb/export/csv.rb', line 71 def self.price_festbetrag(package, lang) package.price(:festbetrag) end |
.price_public(package, lang) ⇒ Object
74 75 76 |
# File 'lib/oddb/export/csv.rb', line 74 def self.price_public(package, lang) package.price(:public) end |
.product(package, language) ⇒ Object
77 78 79 |
# File 'lib/oddb/export/csv.rb', line 77 def self.product(package, language) (product = package.product) && product.name end |
.pzn(package, lang) ⇒ Object
80 81 82 |
# File 'lib/oddb/export/csv.rb', line 80 def self.pzn(package, lang) package.code(:cid) end |
.size(package, language) ⇒ Object
83 84 85 |
# File 'lib/oddb/export/csv.rb', line 83 def self.size(package, language) package.parts.collect { |part| part.to_s(language) }.join('+') end |