Class: ODDB::FiParse::Writer

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

Direct Known Subclasses

FachinfoPDFWriter, FachinfoWriter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWriter

Returns 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

#chaptersObject (readonly)

Returns the value of attribute chapters.



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

def chapters
  @chapters
end

#iksnrsObject (readonly)

Returns the value of attribute iksnrs.



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

def iksnrs
  @iksnrs
end

#nameObject (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

#named_chapter(name) ⇒ Object



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

def named_chapter(name)
	self.instance_eval <<-EOS
		@#{name} = Text::Chapter.new
	EOS
end

#named_chapters(names) ⇒ Object



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

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

#new_alignment(alignment) ⇒ Object



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

#next_chapterObject



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

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

#send_flowing_data(data) ⇒ Object



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

#send_hor_ruleObject



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

#send_line_breakObject



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

#send_literal_data(data) ⇒ Object



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

#set_target(target) ⇒ Object



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