Last active
May 25, 2018 19:07
-
-
Save gosukiwi/135ba8035b3de1595e093a98f7b41156 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SentenceVisitor | |
SENTENCE_VISITORS = { | |
"BOLD" => BoldVisitor, | |
"EMPHASIS" => EmphasisVisitor, | |
"TEXT" => TextVisitor | |
}.freeze | |
def visit(node) | |
visitor_for(node).visit(node) | |
end | |
private | |
def visitor_for(node) | |
SENTENCE_VISITORS.fetch(node.type) { raise "Invalid sentence node type" }.new | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment