Class: ODDB::FiParse::Writer

Inherits:
NullWriter show all
Defined in:
ext/fiparse/src/fiwriter.rb

Direct Known Subclasses

FachinfoPDFWriter, FachinfoWriter

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from NullWriter

#new_fonthandler, #new_linkhandler, #new_tablehandler, #send_image, #send_meta

Constructor Details

- (Writer) initialize

A new instance of Writer



11
12
13
14
15
16
17
18
19
20
# File 'ext/fiparse/src/fiwriter.rb', line 11

def initialize
  super
  @target = nil
  @name = ''
  @section = @header = Text::Section.new 
  @chapters = []
  @templates = named_chapters [
    :company, :galenic_form, :switch
  ]
end

Instance Attribute Details

- (Object) chapters (readonly)

Returns the value of attribute chapters



10
11
12
# File 'ext/fiparse/src/fiwriter.rb', line 10

def chapters
  @chapters
end

- (Object) iksnrs (readonly)

Returns the value of attribute iksnrs



10
11
12
# File 'ext/fiparse/src/fiwriter.rb', line 10

def iksnrs
  @iksnrs
end

- (Object) name (readonly)

Returns the value of attribute name



10
11
12
# File 'ext/fiparse/src/fiwriter.rb', line 10

def name
  @name
end

Instance Method Details

- (Object) named_chapter(name)



65
66
67
# File 'ext/fiparse/src/fiwriter.rb', line 65

def named_chapter(name)
  self.instance_eval "@\#{name} = Text::Chapter.new\n"
end

- (Object) named_chapters(names)



71
72
73
74
75
# File 'ext/fiparse/src/fiwriter.rb', line 71

def named_chapters(names)
  names.collect { |name|
    named_chapter(name)
  }
end

- (Object) new_alignment(alignment)



21
22
23
24
25
26
# File 'ext/fiparse/src/fiwriter.rb', line 21

def new_alignment(alignment)
  target = if(@section)
    @section.next_paragraph
  end
  set_target(target)
end

- (Object) next_chapter



76
77
78
79
80
81
82
# File 'ext/fiparse/src/fiwriter.rb', line 76

def next_chapter
  if(chapter = @chapters.last)
    chapter.clean!
  end
  chapter = @templates.shift || Text::Chapter.new
  @chapters.push(chapter).last
end

- (Object) send_flowing_data(data)



27
28
29
30
# File 'ext/fiparse/src/fiwriter.rb', line 27

def send_flowing_data(data)
  @newline_target = nil
  (@target << data) unless(@target.nil?)
end

- (Object) send_hor_rule



31
32
33
34
35
36
# File 'ext/fiparse/src/fiwriter.rb', line 31

def send_hor_rule
  @chapter.clean! unless @chapter.nil?
  @chapter = nil
  @section = nil
  set_target(nil)
end

- (Object) send_line_break



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'ext/fiparse/src/fiwriter.rb', line 37

def send_line_break
  if(@target == @name)
    @name.strip!
    @name << "\n"
  elsif(@chapter == @galenic_form && @section)
    @section.subheading << "\n"
  elsif(@chapter && (@target == @chapter.heading \
    || @chapter == @galenic_form))
    @chapter.heading << "\n"
  else
    @chapter.clean! unless(@chapter.nil? || @mozilla)
    @newline_target << "\n" unless(@newline_target.nil?)
    target = if(@section)
      @section.next_paragraph
    end
    set_target(target)
  end
end

- (Object) send_literal_data(data)



55
56
57
58
59
60
# File 'ext/fiparse/src/fiwriter.rb', line 55

def send_literal_data(data)
  if(@target)
    @target.preformatted!
    @target << data.gsub(/\r\n?/u, "\n")
  end
end

- (Object) set_target(target)



61
62
63
64
# File 'ext/fiparse/src/fiwriter.rb', line 61

def set_target(target)
  @newline_target = @target unless(target == @target)
  @target = target
end