Class: Rulex::Tex::Writer
Class Method Summary collapse
Instance Method Summary collapse
- #import(arr) ⇒ Object
-
#initialize ⇒ Writer
constructor
A new instance of Writer.
- #to_s ⇒ Object (also: #export)
Constructor Details
#initialize ⇒ Writer
Returns a new instance of Writer.
5 6 7 |
# File 'lib/rulex/tex/writer.rb', line 5 def initialize @content = '' end |
Class Method Details
.to_str(item) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rulex/tex/writer.rb', line 9 def self.to_str item raise TypeError, "item must be a Hash, got #{item}" unless Hash === item raise ArgumentError, ":type must be defined" unless item[:type] case item[:type] when :command raise TypeError, "command name must be a Symbol or a String" unless Symbol === item[:name] or String === item[:name] str = "\\#{item[:name]}" if opts = item[:options] str += '[' + opts.join(',') + ']' end if args = item[:arguments] and not args.empty? str += '{' + args.join('}{') + '}' end str += "\n" when :text res = item[:text] when :environment str = "\\begin{#{item[:name]}}" if args = item[:arguments] and not args.empty? str += '{' + args.join('}{') + '}' end str += "\n" if children = item[:children] str += item[:children].inject(""){|acc, c| acc += Rulex::Tex::Writer.to_str c} end res = str += "\\end{#{item[:name]}}\n" else if item[:children] raise TypeError, "Children must form an array" unless Array === item[:children] str = item[:children].inject(""){|acc, c| acc += Rulex::Tex::Writer.to_str c} if item[:children] else "" end end end |