Class: Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/model/parameter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParameter

Returns a new instance of Parameter.



4
5
6
# File 'lib/model/parameter.rb', line 4

def initialize
  @tokens = []
end

Instance Attribute Details

#documentationObject

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

#columnObject



38
39
40
# File 'lib/model/parameter.rb', line 38

def column
  @tokens.first.column
end

#is_optional?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/model/parameter.rb', line 8

def is_optional?
  @tokens.any? { |token| token.type == :EQUALS }
end

#is_required?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/model/parameter.rb', line 12

def is_required?
  !is_optional?
end

#lineObject



34
35
36
# File 'lib/model/parameter.rb', line 34

def line
  @tokens.first.line
end

#nameObject



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

#tokensObject



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