Module: Opml

Included in:
Reader
Defined in:
lib/opml-reader.rb,
lib/opml-reader/version.rb

Defined Under Namespace

Modules: Reader Classes: OpmlBody

Instance Method Summary collapse

Instance Method Details

#parse(xml_text) ⇒ Object



3
4
5
6
7
8
# File 'lib/opml-reader.rb', line 3

def parse(xml_text)
  parser = Nokogiri::XML(xml_text)
  self.head =set_header_data(parser)
  self.outlines =parse_body(parser)
  self
end

#parse_body(parser) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/opml-reader.rb', line 10

def parse_body(parser)
  outlines = []
  opml_outlines = parser.xpath("//body//outline")
  opml_outlines.each do |opml_outline|
    opml_body =  OpmlBody.new
    opml_outline.attributes.each do |key,value|
      opml_body.outline.merge!(key=>value.value)
    end
    outlines << opml_body
  end
  outlines
end

#set_elements(options = {}) ⇒ Object



23
24
25
# File 'lib/opml-reader.rb', line 23

def set_elements(options={})
  {"title"=>"title","dateCreated"=>"created_date","dateModified"=>"modified_date","ownerName"=>"owner_name","ownerEmail"=>"owner_email"}
end

#set_header_data(parser) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/opml-reader.rb', line 26

def set_header_data(parser)
  header_elements = {}
  opml_header = parser.xpath("//head")
  set_elements.each do |key,field|
    text_data = opml_header.xpath("//#{key}").text
    header_elements.merge!(field=>text_data)
  end
  header_elements
end