Class: ClassParameter
- Inherits:
-
Object
- Object
- ClassParameter
- Defined in:
- lib/model/class_parameter.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #add(token) ⇒ Object
- #column ⇒ Object
-
#initialize ⇒ ClassParameter
constructor
A new instance of ClassParameter.
- #is_optional? ⇒ Boolean
- #is_required? ⇒ Boolean
- #line ⇒ Object
- #name ⇒ Object
- #tokens ⇒ Object
Constructor Details
#initialize ⇒ ClassParameter
Returns a new instance of ClassParameter.
2 3 4 |
# File 'lib/model/class_parameter.rb', line 2 def initialize @tokens = [] end |
Instance Method Details
#<=>(other) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/model/class_parameter.rb', line 40 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
20 21 22 23 24 25 |
# File 'lib/model/class_parameter.rb', line 20 def add(token) # A parameter never starts with a newline token unless @tokens.empty? && token.type == :NEWLINE @tokens << token end end |
#column ⇒ Object
36 37 38 |
# File 'lib/model/class_parameter.rb', line 36 def column @tokens.first.column end |
#is_optional? ⇒ Boolean
6 7 8 |
# File 'lib/model/class_parameter.rb', line 6 def is_optional? @tokens.any? { |token| token.type == :EQUALS } end |
#is_required? ⇒ Boolean
10 11 12 |
# File 'lib/model/class_parameter.rb', line 10 def is_required? !is_optional? end |
#line ⇒ Object
32 33 34 |
# File 'lib/model/class_parameter.rb', line 32 def line @tokens.first.line end |
#name ⇒ Object
14 15 16 17 18 |
# File 'lib/model/class_parameter.rb', line 14 def name @tokens.select do |token| token.type == :VARIABLE end.first.value end |
#tokens ⇒ Object
27 28 29 30 |
# File 'lib/model/class_parameter.rb', line 27 def tokens sanitized_tokens = strip_starting_newlines(@tokens) return strip_ending_newlines(sanitized_tokens) end |