Class: Oddb2xml::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/oddb2xml/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Builder

Returns a new instance of Builder.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/oddb2xml/builder.rb', line 43

def initialize(args = {})
  @options    = args
  @subject    = nil
  @refdata    = {}
  @items      = {} # Items from Preparations.xml in BAG, using GTINs as key
  @flags      = {}
  @lppvs      = {}
  @infos      = {}
  @packs      = {}
  @migel      = {}
  @infos_zur_rose     = {} # zurrose
  @actions    = []
  @orphans    = []
  @fridges    = []
  @ean14      = false
  @companies  = []
  @people     = []
  @tag_suffix = nil
  @pharmacode = {} # index pharmacode => item
  if block_given?
    yield self
  end
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def actions
  @actions
end

#companiesObject

Returns the value of attribute companies.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def companies
  @companies
end

#ean14Object

Returns the value of attribute ean14.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def ean14
  @ean14
end

#flagsObject

Returns the value of attribute flags.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def flags
  @flags
end

#fridgesObject

Returns the value of attribute fridges.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def fridges
  @fridges
end

#infosObject

Returns the value of attribute infos.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def infos
  @infos
end

#infos_zur_roseObject

Returns the value of attribute infos_zur_rose.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def infos_zur_rose
  @infos_zur_rose
end

#itemsObject

Returns the value of attribute items.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def items
  @items
end

#lppvsObject

Returns the value of attribute lppvs.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def lppvs
  @lppvs
end

#migelObject

Returns the value of attribute migel.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def migel
  @migel
end

#orphansObject

Returns the value of attribute orphans.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def orphans
  @orphans
end

#packsObject

Returns the value of attribute packs.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def packs
  @packs
end

#peopleObject

Returns the value of attribute people.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def people
  @people
end

#refdataObject

Returns the value of attribute refdata.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def refdata
  @refdata
end

#subjectObject

Returns the value of attribute subject.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def subject
  @subject
end

#tag_suffixObject

Returns the value of attribute tag_suffix.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def tag_suffix
  @tag_suffix
end

#xsdObject

Returns the value of attribute xsd.



37
38
39
# File 'lib/oddb2xml/builder.rb', line 37

def xsd
  @xsd
end

Instance Method Details

#emit_substance(xml, substance, emit_active = false) ⇒ Object



625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
# File 'lib/oddb2xml/builder.rb', line 625

def emit_substance(xml, substance, emit_active=false)
    xml.MORE_INFO substance.more_info if substance.more_info
    xml.SUBSTANCE_NAME substance.name
    xml.IS_ACTIVE_AGENT substance.is_active_agent if emit_active
    if substance.dose
      if substance.qty.is_a?(Float) or substance.qty.is_a?(Fixnum)
        xml.QTY  substance.qty
        xml.UNIT substance.unit
      else
        xml.DOSE_TEXT substance.dose.to_s
      end
    end
    if substance.chemical_substance
      xml.CHEMICAL_SUBSTANCE {
        emit_substance(xml, substance.chemical_substance)
      }
    end
    if substance.salts and substance.salts.size > 0
      xml.SALTS {
        substance.salts.each { |salt|
          xml.SALT {
            emit_substance(xml, salt)
                   }
                             }
        }

    end
end

#to_dat(subject = nil) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/oddb2xml/builder.rb', line 74

def to_dat(subject=nil)
  Oddb2xml.log  "to_dat subject #{subject ? subject.to_s :  @subject.to_s} for #{self.class}"
  if subject
    self.send('build_' + subject.to_s)
  elsif @subject
    self.send('build_' + @subject.to_s)
  end
end

#to_xml(subject = nil) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/oddb2xml/builder.rb', line 66

def to_xml(subject=nil)
  Oddb2xml.log "to_xml subject #{subject} #{@subject} for #{self.class}"
  if subject
    self.send('build_' + subject.to_s)
  elsif @subject
    self.send('build_' + @subject.to_s)
  end
end