Class: ODDB::Export::Csv::Packages

Inherits:
Object
  • Object
show all
Defined in:
lib/oddb/export/csv.rb

Instance Method Summary collapse

Instance Method Details

#active_agents(package, lang) ⇒ Object



37
38
39
# File 'lib/oddb/export/csv.rb', line 37

def active_agents(package, lang)
  package.active_agents.join('|')
end

#atc_line(atc, language) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/oddb/export/csv.rb', line 26

def 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



40
41
42
43
44
45
46
47
# File 'lib/oddb/export/csv.rb', line 40

def 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, io = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/oddb/export/csv.rb', line 10

def export(packages, components, language = :de, io=nil)
  atcs = partition packages
  str = FasterCSV.generate { |csv|
    atcs.each { |list|
      csv << atc_line(list.atc, language)
      list.each { |pac|
        csv << package_line(pac, components, language)
      }
    }
  }
  if io
    io << str
  else
    str
  end
end

#package_line(package, components, language) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/oddb/export/csv.rb', line 48

def 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



63
64
65
66
67
68
69
70
71
72
# File 'lib/oddb/export/csv.rb', line 63

def 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



73
74
75
# File 'lib/oddb/export/csv.rb', line 73

def price_exfactory(package, lang)
  package.price(:exfactory)
end

#price_festbetrag(package, lang) ⇒ Object



76
77
78
# File 'lib/oddb/export/csv.rb', line 76

def price_festbetrag(package, lang)
  package.price(:festbetrag)
end

#price_public(package, lang) ⇒ Object



79
80
81
# File 'lib/oddb/export/csv.rb', line 79

def price_public(package, lang)
  package.price(:public)
end

#product(package, language) ⇒ Object



82
83
84
# File 'lib/oddb/export/csv.rb', line 82

def product(package, language)
  (product = package.product) && product.name
end

#pzn(package, lang) ⇒ Object



85
86
87
# File 'lib/oddb/export/csv.rb', line 85

def pzn(package, lang)
  package.code(:cid)
end

#size(package, language) ⇒ Object



88
89
90
# File 'lib/oddb/export/csv.rb', line 88

def size(package, language)
  package.parts.collect { |part| part.to_s(language) }.join('+')
end