Class: WebIDL::Generator
- Inherits:
-
Object
- Object
- WebIDL::Generator
- Defined in:
- lib/webidl/generator.rb
Defined Under Namespace
Classes: ParseError
Instance Method Summary collapse
- #generate(input) ⇒ Object
-
#initialize(visitor = nil) ⇒ Generator
constructor
A new instance of Generator.
Constructor Details
#initialize(visitor = nil) ⇒ Generator
Returns a new instance of Generator.
6 7 8 |
# File 'lib/webidl/generator.rb', line 6 def initialize(visitor = nil) @visitor = visitor end |
Instance Method Details
#generate(input) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/webidl/generator.rb', line 10 def generate(input) ast_defs = case input when String parse(input) when Array input.each do |e| unless e.kind_of? WebIDL::Ast::Node raise TypeError, "input Array elements must be of WebIDL::Ast::Node (got #{e.class})" end end input when WebIDL::Ast::Node [input] else raise TypeError, "unexpected input #{input.class}" end strings = ast_defs.map { |definition| ruby2ruby.process definition.accept(visitor) }.compact strings.join("\n\n") end |