Class: CabbageDoc::Example

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Parser

included, #parse_option, #parse_templates

Constructor Details

#initializeExample

Returns a new instance of Example.



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

def initialize
  @params = {}
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Instance Method Details

#parse(text, tag = TAG) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/cabbage_doc/example.rb', line 13

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

  @label = m[1].strip
  @params = parse_option(m[2].strip)

  valid?
end

#to_queryObject



23
24
25
# File 'lib/cabbage_doc/example.rb', line 23

def to_query
  params.map { |k, v| "#{k}=#{CGI.escape(v)}" }.join("&")
end

#valid?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/cabbage_doc/example.rb', line 27

def valid?
  !@label.nil?
end