Class: Decode::Comment::Parameter

Inherits:
Tag
  • Object
show all
Defined in:
lib/decode/comment/parameter.rb

Overview

Represents a named method parameter.

  • ‘@parameter age [Float] The users age.`

Direct Known Subclasses

Option

Constant Summary collapse

PATTERN =
/\A(?<name>.*?)\s+\[#{Tag.bracketed_content(:type)}\](\s+(?<details>.*?))?\Z/

Instance Attribute Summary collapse

Attributes inherited from Tag

#The directive that generated the tag., #directive

Attributes inherited from Node

#The children of this node., #children

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tag

bracketed_content, match, parse

Methods inherited from Node

#add, #children?, #each, #filter, #text, #traverse

Constructor Details

#initialize(directive, name, type) ⇒ Parameter

Initialize a new parameter.



39
40
41
42
43
44
# File 'lib/decode/comment/parameter.rb', line 39

def initialize(directive, name, type)
  super(directive)
  
  @name = name
  @type = type
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



47
48
49
# File 'lib/decode/comment/parameter.rb', line 47

def name
  @name
end

#The name of the parameter.(nameoftheparameter.) ⇒ Object (readonly)



47
# File 'lib/decode/comment/parameter.rb', line 47

attr :name

#The type of the parameter.(typeoftheparameter.) ⇒ Object (readonly)



50
# File 'lib/decode/comment/parameter.rb', line 50

attr :type

#typeObject (readonly)

Returns the value of attribute type.



50
51
52
# File 'lib/decode/comment/parameter.rb', line 50

def type
  @type
end

Class Method Details

.build(directive, match) ⇒ Object

Build a parameter from a directive and regex match.



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/decode/comment/parameter.rb', line 22

def self.build(directive, match)
  name = match[:name] or raise ArgumentError, "Missing name in parameter match!"
  type = match[:type] or raise ArgumentError, "Missing type in parameter match!"
  
  node = self.new(directive, name, type)
  
  if details = match[:details]
    node.add(Text.new(details))
  end
  
  return node
end