Class: Democritus::FromJsonClassBuilder
- Inherits:
-
Object
- Object
- Democritus::FromJsonClassBuilder
- Defined in:
- lib/democritus/from_json_class_builder.rb
Overview
This is a class with a greater “reek” than I would like. However, it is parsing JSON and loading that into ruby; Its complicated. So I’m willing to accept and assume responsibility for this code “reek”.
Responsible for building a class based on the given JSON document.
Note the following structure:
Commands that are called against the builder are Hash keys that start with ‘#’. Keywords are command parameters that do not start with ‘#’.
Constant Summary collapse
- KEY_IS_COMMAND_REGEXP =
Used to answer the question “Does the given Hash key represent a command?”
/\A\#(.+)$/.freeze
Instance Method Summary collapse
-
#generate_class ⇒ Object
A wrapper around the Democritus::ClassBuilder#generate_class.
-
#initialize(json_document) ⇒ FromJsonClassBuilder
constructor
A new instance of FromJsonClassBuilder.
Constructor Details
#initialize(json_document) ⇒ FromJsonClassBuilder
Returns a new instance of FromJsonClassBuilder.
25 26 27 |
# File 'lib/democritus/from_json_class_builder.rb', line 25 def initialize(json_document) self.data = json_document end |
Instance Method Details
#generate_class ⇒ Object
A wrapper around the Democritus::ClassBuilder#generate_class. However instead of evaulating blocks, the builder must be called directly.
45 46 47 48 49 50 |
# File 'lib/democritus/from_json_class_builder.rb', line 45 def generate_class keywords, nested_commands = extract_keywords_and_nested_commands(node: data) class_builder = ClassBuilder.new(**keywords) build(node: nested_commands, class_builder: class_builder) class_builder.generate_class end |