Class: Rulex::Rex::Reader
- Inherits:
-
Object
- Object
- Rulex::Rex::Reader
show all
- Defined in:
- lib/rulex/rex/reader.rb
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Reader
Returns a new instance of Reader.
5
6
7
8
9
|
# File 'lib/rulex/rex/reader.rb', line 5
def initialize
@content = []
@content_stack = [@content]
@latex_reader = Rulex::Tex::Reader.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m_id, *args, &block) ⇒ Object
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/rulex/rex/reader.rb', line 68
def method_missing(m_id, *args, &block)
if block
tex_environment(m_id, args, block)
elsif /pure_([a-zA-Z]+)/.match(m_id)
Rulex::Tex::Writer.to_str(build_tex_command($1,args))
else
tex_command(m_id, args)
end
end
|
Instance Method Details
#add_to_content(node) ⇒ Object
13
14
15
|
# File 'lib/rulex/rex/reader.rb', line 13
def add_to_content node
@content_stack.last << node
end
|
#build_tex_command(name, params) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/rulex/rex/reader.rb', line 33
def build_tex_command(name, params)
case params.length
when 1
{type: :command, name: name, arguments: params}
when 2
first = params[0]
second = params[1]
if Array === params[0] && Array === params[1]
{type: :command, name: name, arguments: second, options: first}
elsif String === params[0] && String === params[1]
{type: :command, name: name, arguments: [first, second]}
else
error "something is not quite right with the parameters"
end
else
error "wrong number of params"
end
end
|
#depth ⇒ Object
56
57
58
|
# File 'lib/rulex/rex/reader.rb', line 56
def depth
@content_stack.length - 1
end
|
#export ⇒ Object
29
30
31
|
# File 'lib/rulex/rex/reader.rb', line 29
def export
@content
end
|
#import(filepath) ⇒ Object
25
26
27
|
# File 'lib/rulex/rex/reader.rb', line 25
def import filepath
read File.open(filepath).read
end
|
#raw(str) ⇒ Object
17
18
19
|
# File 'lib/rulex/rex/reader.rb', line 17
def raw str
add_to_content(type: :text, text: str)
end
|
#tex(str) ⇒ Object
21
22
23
|
# File 'lib/rulex/rex/reader.rb', line 21
def tex str
add_to_content(type: :tex, children: @latex_reader.read(str))
end
|
#tex_command(name, params) ⇒ Object
52
53
54
|
# File 'lib/rulex/rex/reader.rb', line 52
def tex_command(name, params)
add_to_content build_tex_command name, params
end
|
#tex_environment(name, args, block) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/rulex/rex/reader.rb', line 60
def tex_environment(name, args, block)
new_node = {type: :environment, name: name, arguments: args}
@content_stack.push []
read &block
new_node.merge!(children: @content_stack.pop)
add_to_content new_node
end
|