Class: ApiGuides::Example
- Inherits:
-
Object
- Object
- ApiGuides::Example
- Defined in:
- lib/api_guides/example.rb
Overview
This class models an example for your documentation. It is for a specific language and contains a raw markdown formatted string. A diffrent version of the documentation will be generated for each language with examples.
You never interact with this class directly.
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#language ⇒ Object
Returns the value of attribute language.
Class Method Summary collapse
-
.from_xml(xml) ⇒ Object
Takes an XML representation and parse it into an Example instance.
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Example
constructor
A new instance of Example.
Constructor Details
#initialize(attributes = {}) ⇒ Example
Returns a new instance of Example.
14 15 16 17 18 |
# File 'lib/api_guides/example.rb', line 14 def initialize(attributes = {}) attributes.each_pair do |attr, value| send "#{attr}=", value end end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
12 13 14 |
# File 'lib/api_guides/example.rb', line 12 def content @content end |
#language ⇒ Object
Returns the value of attribute language.
11 12 13 |
# File 'lib/api_guides/example.rb', line 11 def language @language end |
Class Method Details
.from_xml(xml) ⇒ Object
Takes an XML representation and parse it into an Example instance.
Here is XML format expected:
<examle language="Foo">
<![CDATA[
Insert your markdown here
]]>
</reference>
This would set ‘#language` to ’Foo’ and #content to ‘Insert your markdown here’
33 34 35 36 |
# File 'lib/api_guides/example.rb', line 33 def self.from_xml(xml) doc = Nokogiri::XML.parse(xml).at_xpath('//example') Example.new :language => doc.attributes['language'].try(:value), :content => doc.content end |