Class: Parameter
- Inherits:
-
Object
- Object
- Parameter
- Defined in:
- lib/model/parameter.rb
Defined Under Namespace
Classes: SyntaxError
Instance Attribute Summary collapse
-
#documentation ⇒ Object
Returns the value of attribute documentation.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #add(token) ⇒ Object
- #column ⇒ Object
-
#initialize ⇒ Parameter
constructor
A new instance of Parameter.
- #is_optional? ⇒ Boolean
- #is_required? ⇒ Boolean
- #line ⇒ Object
- #name ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize ⇒ Parameter
Returns a new instance of Parameter.
5 6 7 |
# File 'lib/model/parameter.rb', line 5 def initialize @tokens = [] end |
Instance Attribute Details
#documentation ⇒ Object
Returns the value of attribute documentation.
3 4 5 |
# File 'lib/model/parameter.rb', line 3 def documentation @documentation end |
Instance Method Details
#<=>(other) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 |
# 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 ⇒ Object
40 41 42 |
# File 'lib/model/parameter.rb', line 40 def column @tokens.first.column end |
#is_optional? ⇒ Boolean
9 10 11 |
# File 'lib/model/parameter.rb', line 9 def is_optional? @tokens.any? { |token| token.type == :EQUALS } end |
#is_required? ⇒ Boolean
13 14 15 |
# File 'lib/model/parameter.rb', line 13 def is_required? !is_optional? end |
#line ⇒ Object
36 37 38 |
# File 'lib/model/parameter.rb', line 36 def line @tokens.first.line end |
#name ⇒ Object
17 18 19 20 21 |
# File 'lib/model/parameter.rb', line 17 def name @tokens.select do |token| token.type == :VARIABLE end.first.value end |
#tokens ⇒ Object
32 33 34 |
# File 'lib/model/parameter.rb', line 32 def tokens strip_newlines(@tokens) end |