Class: Xdt::Ldt::LGReport
- Inherits:
-
Object
- Object
- Xdt::Ldt::LGReport
- Defined in:
- lib/xdt/ldt.rb
Instance Method Summary collapse
-
#initialize {|_self| ... } ⇒ LGReport
constructor
A new instance of LGReport.
- #length ⇒ Object
- #section(id, &blk) ⇒ Object
- #to_s ⇒ Object
-
#write_file(filename) ⇒ Object
only write the file if it contains any sections.
Constructor Details
#initialize {|_self| ... } ⇒ LGReport
Returns a new instance of LGReport.
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
#length ⇒ Object
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_s ⇒ Object
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 |