Class: CabbageDoc::Example
- Inherits:
-
Object
- Object
- CabbageDoc::Example
- Includes:
- Parser
- Defined in:
- lib/cabbage_doc/example.rb
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize ⇒ Example
constructor
A new instance of Example.
- #parse(text, tag = TAG) ⇒ Object
- #to_query ⇒ Object
- #valid? ⇒ Boolean
Methods included from Parser
included, #parse_option, #parse_templates
Constructor Details
#initialize ⇒ Example
Returns a new instance of Example.
9 10 11 |
# File 'lib/cabbage_doc/example.rb', line 9 def initialize @params = {} end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
7 8 9 |
# File 'lib/cabbage_doc/example.rb', line 7 def label @label end |
#params ⇒ Object (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_query ⇒ Object
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
27 28 29 |
# File 'lib/cabbage_doc/example.rb', line 27 def valid? !@label.nil? end |