Class: Xdt::Ldt::LGReport

Inherits:
Object
  • Object
show all
Defined in:
lib/xdt/ldt.rb

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ LGReport

Returns a new instance of LGReport.

Yields:

  • (_self)

Yield Parameters:



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
# File 'lib/xdt/ldt.rb', line 42

def initialize
  @sections = []

  section("8220") do |s|
    s.field("9211", "07/99")
    # s.field("0201", "") # Arztnummer
    s.field("0203", "Alexander")  # Arztname
    s.field("0204", "Nuklearmediziner") # Arztgruppe
    s.field("0205", "Schönhauser Allee 82") # Strasse
    s.field("0206", "10439 Berlin") # PLZ Ort
    s.field("8300", "LABOR Schoenhauser Allee 82")
    # s.field("0101", "") # KBV Prüfnummer
    s.field("9106", "3") # Charset (iso-8859-1)
    s.field("8312", "1") # Kundennummer
    s.field("9103", Date.today.strftime("%d%m%Y"))
  end

  yield self if block_given?

  section("8221") do |s|
    overhead = 44
    s.field("9202", (length + overhead).to_s.rjust(8,"0"))
  end

end

Instance Method Details

#lengthObject



68
69
70
# File 'lib/xdt/ldt.rb', line 68

def length
  @sections.inject(0) { |sum, section| sum + section.length }
end

#section(id, &blk) ⇒ Object



38
39
40
# File 'lib/xdt/ldt.rb', line 38

def section(id, &blk)
  @sections << Xdt::Section.new(id, &blk)
end

#to_sObject



72
73
74
# File 'lib/xdt/ldt.rb', line 72

def to_s
  @sections.map { |pkg| pkg.to_s }.join
end

#write_file(filename) ⇒ Object

only write the file if it contains any sections



28
29
30
31
32
33
34
35
36
# File 'lib/xdt/ldt.rb', line 28

def write_file(filename)
  return false unless @sections.length > 2

  File.open(filename, "w+") do |f|
    f.write self.to_s
  end

  return true
end