Class: Chelsy::Translator
- Inherits:
-
Object
- Object
- Chelsy::Translator
- Defined in:
- lib/chelsy/translator.rb
Constant Summary collapse
- DEFAULT_INDENT_STRING =
' '.freeze
Instance Attribute Summary collapse
-
#indent_level ⇒ Object
Returns the value of attribute indent_level.
-
#indent_string ⇒ Object
Returns the value of attribute indent_string.
Instance Method Summary collapse
-
#initialize(indent_string: DEFAULT_INDENT_STRING, indent_level: 0) ⇒ Translator
constructor
A new instance of Translator.
- #translate(node) ⇒ Object
Constructor Details
#initialize(indent_string: DEFAULT_INDENT_STRING, indent_level: 0) ⇒ Translator
Returns a new instance of Translator.
8 9 10 11 |
# File 'lib/chelsy/translator.rb', line 8 def initialize(indent_string: DEFAULT_INDENT_STRING, indent_level: 0) @indent_string = indent_string @indent_level = indent_level end |
Instance Attribute Details
#indent_level ⇒ Object
Returns the value of attribute indent_level.
4 5 6 |
# File 'lib/chelsy/translator.rb', line 4 def indent_level @indent_level end |
#indent_string ⇒ Object
Returns the value of attribute indent_string.
4 5 6 |
# File 'lib/chelsy/translator.rb', line 4 def indent_string @indent_string end |
Instance Method Details
#translate(node) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/chelsy/translator.rb', line 13 def translate(node) case node when Element translate_element(node) when Node translate_node(node) when Symbol translate_ident(node) when String translate_fragment(node) else raise ArgumentError, "Unrecognized AST node: #{node.inspect}" end end |