Class: Parameter
- Inherits:
-
Object
- Object
- Parameter
- Defined in:
- lib/model/parameter.rb
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.
4 5 6 |
# File 'lib/model/parameter.rb', line 4 def initialize @tokens = [] end |
Instance Attribute Details
#documentation ⇒ Object
Returns the value of attribute documentation.
2 3 4 |
# File 'lib/model/parameter.rb', line 2 def documentation @documentation end |
Instance Method Details
#<=>(other) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/model/parameter.rb', line 42 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
22 23 24 25 26 27 |
# File 'lib/model/parameter.rb', line 22 def add(token) # A parameter never starts with a newline token unless @tokens.empty? && token.type == :NEWLINE @tokens << token end end |
#column ⇒ Object
38 39 40 |
# File 'lib/model/parameter.rb', line 38 def column @tokens.first.column end |
#is_optional? ⇒ Boolean
8 9 10 |
# File 'lib/model/parameter.rb', line 8 def is_optional? @tokens.any? { |token| token.type == :EQUALS } end |
#is_required? ⇒ Boolean
12 13 14 |
# File 'lib/model/parameter.rb', line 12 def is_required? !is_optional? end |
#line ⇒ Object
34 35 36 |
# File 'lib/model/parameter.rb', line 34 def line @tokens.first.line end |
#name ⇒ Object
16 17 18 19 20 |
# File 'lib/model/parameter.rb', line 16 def name @tokens.select do |token| token.type == :VARIABLE end.first.value end |
#tokens ⇒ Object
29 30 31 32 |
# File 'lib/model/parameter.rb', line 29 def tokens sanitized_tokens = strip_starting_newlines(@tokens) return strip_ending_newlines(sanitized_tokens) end |