Class: ApiGuides::Example

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



12
13
14
# File 'lib/api_guides/example.rb', line 12

def content
  @content
end

#languageObject

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