Class: ApiGuides::Reference

Inherits:
Object
  • Object
show all
Defined in:
lib/api_guides/reference.rb

Overview

This class models a <reference> element in a document. It will always be shown with the associated section. All references will be combined into an index.

References can also be linked to using standard markdown syntax with some sugar provided by this library.

Each reference has a title. The title is used for linking and descirbing each reference. You should markdown inside each reference to fill in your content

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Reference

Returns a new instance of Reference.



18
19
20
21
22
# File 'lib/api_guides/reference.rb', line 18

def initialize(attributes = {})
  attributes.each_pair do |attr, value|
    send "#{attr}=", value
  end
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



16
17
18
# File 'lib/api_guides/reference.rb', line 16

def content
  @content
end

#titleObject

Returns the value of attribute title.



16
17
18
# File 'lib/api_guides/reference.rb', line 16

def title
  @title
end

Class Method Details

.from_xml(xml) ⇒ Object

Takes an XML representation and parse it into a Reference instance.

Here is XML format expected:

<reference title="Foo">
  <![CDATA[
  Insert your markdown here
  ]]>
</reference>

This would set ‘#title` to ’Foo’ and #content to ‘Insert your markdown here’



37
38
39
40
# File 'lib/api_guides/reference.rb', line 37

def self.from_xml(xml)
  doc = Nokogiri::XML.parse(xml).at_xpath('//reference')
  Reference.new :title => doc.attributes['title'].try(:value), :content => doc.content
end