Class: CabbageDoc::Parameter

Inherits:
Object
  • Object
show all
Includes:
Parser
Defined in:
lib/cabbage_doc/parameter.rb

Constant Summary collapse

TYPES =
i(numeric decimal integer string id enumeration array date time timestamp hash)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

included, #parse_option, #parse_templates

Constructor Details

#initializeParameter

Returns a new instance of Parameter.



9
10
11
# File 'lib/cabbage_doc/parameter.rb', line 9

def initialize
  @values = []
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



7
8
9
# File 'lib/cabbage_doc/parameter.rb', line 7

def default
  @default
end

#labelObject (readonly)

Returns the value of attribute label.



7
8
9
# File 'lib/cabbage_doc/parameter.rb', line 7

def label
  @label
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/cabbage_doc/parameter.rb', line 7

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



7
8
9
# File 'lib/cabbage_doc/parameter.rb', line 7

def required
  @required
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/cabbage_doc/parameter.rb', line 7

def type
  @type
end

#type_labelObject (readonly)

Returns the value of attribute type_label.



7
8
9
# File 'lib/cabbage_doc/parameter.rb', line 7

def type_label
  @type_label
end

#valuesObject (readonly)

Returns the value of attribute values.



7
8
9
# File 'lib/cabbage_doc/parameter.rb', line 7

def values
  @values
end

Instance Method Details

#parse(text, tag = TAG) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cabbage_doc/parameter.rb', line 13

def parse(text, tag = TAG)
  m = text.match(/^(.*?\s+\(.*?\).*?)\s+-\s+(.*?)$/)
  return false unless m

  @name, @type_label, @required = parse_name_type_required(m[1].strip)
  @type = @type_label.downcase.to_sym if @type_label

  @required = !!@required

  @label, @default, @values = parse_label_default_values(m[2].strip)
  @values ||= []

  valid?
end

#valid?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/cabbage_doc/parameter.rb', line 28

def valid?
  @type && TYPES.include?(@type)
end