Created
January 13, 2015 02:07
-
-
Save jadehopepunk/21e00c09f7a9342f8a91 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 IndentManager | |
def initialize | |
@indents = [] | |
@parse_complete = false | |
end | |
def register_indent(indent) | |
@indents << indent | |
end | |
def parse_complete! | |
@parse_complete = true | |
end | |
def normalize(value) | |
value * normalization_factor | |
end | |
private | |
def normalization_factor | |
raise RuntimeError.new("you can't normalize until you have finished parsing") unless @parse_complete | |
@normalization_factor ||= compute_normalization_factor | |
end | |
def compute_normalization_factor | |
# loop through @indents and figure out normalization | |
end | |
end | |
class Indent | |
def initialize(value, indent_manager) | |
@value = value | |
@indent_manager = indent_manager | |
@indent_manager.register_indent(self) | |
end | |
def unnormalised | |
@value | |
end | |
def normalized | |
@indent_manager.normalize(value) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment