Class: UDRS::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/udrs/document.rb

Constant Summary collapse

TYPES =
%i(pdf escp)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ Document

Returns a new instance of Document.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/udrs/document.rb', line 12

def initialize(type)
	fail ArgumentError, "Unknown udrs type #{type}" unless TYPES.include?(type)
	@type = type
	case type
		when :pdf
			@renderer = Renderers::PDFRenderer.new
		when :escp
			@renderer = Renderers::ESCPRenderer.new
	end

	@container = Components::Container.new
	@rendering = false
end

Instance Attribute Details

#is_renderingObject (readonly)

Returns the value of attribute is_rendering.



8
9
10
# File 'lib/udrs/document.rb', line 8

def is_rendering
  @is_rendering
end

Instance Method Details

#code(*args) ⇒ Object



59
60
61
# File 'lib/udrs/document.rb', line 59

def code(*args)
	add_component(Components::Code.new(*args))
end

#end_page(*args) ⇒ Object

Add components



35
36
37
# File 'lib/udrs/document.rb', line 35

def end_page(*args)
	add_component(Components::PageEnd.new(*args))
end

#escp?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/udrs/document.rb', line 30

def escp?
	return @type == :escp
end


68
69
70
71
72
# File 'lib/udrs/document.rb', line 68

def footer(*args, &block)
	footer = Components::Footer.new(*args)
	using_container(footer, &block)
	add_component(footer)
end

#logo(*args) ⇒ Object



56
57
58
# File 'lib/udrs/document.rb', line 56

def (*args)
	add_component(Components::Logo.new(*args))
end

#pdf?Boolean

Check the document type

Returns:

  • (Boolean)


27
28
29
# File 'lib/udrs/document.rb', line 27

def pdf?
	return @type == :pdf
end

#raw(*args, &block) ⇒ Object



65
66
67
# File 'lib/udrs/document.rb', line 65

def raw(*args, &block)
	add_component(Components::Raw.new(*args, &block))
end

#renderObject

Render the components using the renderer



75
76
77
78
79
80
81
82
# File 'lib/udrs/document.rb', line 75

def render
	unless @rendered
		@is_rendering = true
		@rendered = @renderer.render(@container)
		@is_rendering = false
	end
	return @rendered
end

#render!Object



83
84
85
86
# File 'lib/udrs/document.rb', line 83

def render!
	@rendered = nil
	return render
end

#section(txt) ⇒ Object



41
42
43
# File 'lib/udrs/document.rb', line 41

def section(txt)
	add_component(Components::Header.new(txt, 1))
end

#spacer(*args) ⇒ Object



38
39
40
# File 'lib/udrs/document.rb', line 38

def spacer(*args)
	add_component(Components::Spacer.new(*args))
end

#subsection(txt) ⇒ Object



44
45
46
# File 'lib/udrs/document.rb', line 44

def subsection(txt)
	add_component(Components::Header.new(txt, 2))
end

#subsubsection(txt) ⇒ Object



47
48
49
# File 'lib/udrs/document.rb', line 47

def subsubsection(txt)
	add_component(Components::Header.new(txt, 3))
end

#table(*args, &block) ⇒ Object



62
63
64
# File 'lib/udrs/document.rb', line 62

def table(*args, &block)
	add_component(Components::Table.new(*args, &block))
end

#text(*args) ⇒ Object



50
51
52
# File 'lib/udrs/document.rb', line 50

def text(*args)
	add_component(Components::Text.new(*args))
end

#ttext(*args) ⇒ Object



53
54
55
# File 'lib/udrs/document.rb', line 53

def ttext(*args)
	add_component(Components::TText.new(*args))
end