class Parameter
Attributes
documentation[RW]
Public Class Methods
new()
click to toggle source
# File lib/model/parameter.rb, line 5 def initialize @tokens = [] end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/model/parameter.rb, line 44 def <=>(other) if (self.is_optional? && other.is_optional?) || (self.is_required? && other.is_required?) return self.name <=> other.name elsif self.is_optional? && other.is_required? return 1 else return -1 end end
add(token)
click to toggle source
# File lib/model/parameter.rb, line 23 def add(token) # A parameter never starts with a newline token, so skip that one return if @tokens.empty? && token.type == :NEWLINE # Raise a syntax error if the parameter starts with a comma. raise SyntaxError, "Syntax error: Expected a parameter definition, found comma on line #{token.line}, column #{token.column}" if @tokens.empty? && token.type == :COMMA @tokens << token end
column()
click to toggle source
# File lib/model/parameter.rb, line 40 def column @tokens.first.column end
is_optional?()
click to toggle source
# File lib/model/parameter.rb, line 9 def is_optional? @tokens.any? { |token| token.type == :EQUALS } end
is_required?()
click to toggle source
# File lib/model/parameter.rb, line 13 def is_required? !is_optional? end
line()
click to toggle source
# File lib/model/parameter.rb, line 36 def line @tokens.first.line end
name()
click to toggle source
# File lib/model/parameter.rb, line 17 def name @tokens.select do |token| token.type == :VARIABLE end.first.value end
tokens()
click to toggle source
# File lib/model/parameter.rb, line 32 def tokens strip_newlines(@tokens) end
Private Instance Methods
strip_ending_newlines(tokens)
click to toggle source
# File lib/model/parameter.rb, line 69 def strip_ending_newlines(tokens) strip_starting_newlines(tokens.reverse).reverse end
strip_newlines(tokens)
click to toggle source
# File lib/model/parameter.rb, line 55 def strip_newlines(tokens) stripped_tokens = strip_starting_newlines(tokens) strip_ending_newlines(stripped_tokens) end
strip_starting_newlines(tokens)
click to toggle source
# File lib/model/parameter.rb, line 60 def strip_starting_newlines(tokens) tokens.inject([]) do |memo, token| unless memo.empty? && token.type == :NEWLINE memo << token end memo end end