Representer
Inherits Reference < Object
Representer allows to be integrated with other programs easilly through its API.
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.representation
# => "def PLACEHOLDER_1\n 1 + 1\nend"
Instance methods
Returns a json formatted String with the debug information.
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.debug_json
# => "[["PLACEHOLDER_1", "Crystal::Def"]]"
Returns a mapping of the replaced names to the original names.
The format returned is a json formatted String.
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.mapping
# => "{\"PLACEHOLDER_1\":\"foo\"}"
Parses a single file by reading it and then parsing it with the Crystal parser.
path = Path.new("path/to/file")
represent = Representer.new
represent.parse_file(path)
Parses specified files in a folder by grouping them into a single long String
and then parsing that String with the Crystal parser.
path = Path.new("path/to/folder")
represent = Representer.new
represent.parse_folder(path, ["main.cr"])
Parses all files in a folder by grouping them into a single long String
and then parsing that String with the Crystal parser.
path = Path.new("path/to/folder")
represent = Representer.new
represent.parse_folder(path)
Parses a String by parsing it with the Crystal parser.
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
Returns a version number for the representation format.
The format returned is a json formatted String.
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.representation_json
# => "{\"version\":1}"
Allows changing the value of the counter which is which number of the placeholder item gets. When wanting to represent brand new code, this variable has to be changed to one. When the method is called without any argumments will it defualt to one.
Example:
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.update_data([] of String)
represent.update_counter(1)
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
Allows changing the value of the data variable which is what is holding all names when representation. When wanting to represent brand new code, this variable has to be cleared
Example:
represent = Representer.new
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent
represent.update_data([] of String)
represent.update_counter
represent.parse_string("def foo\n 1 + 1\nend")
represent.represent