class Opml

Attributes

outlines[R]

Public Class Methods

new(xml) click to toggle source
# File lib/opml.rb, line 50
def initialize(xml)
  @doc = REXML::Document.new(xml)

  parse_head_elements :title, :owner_name, :owner_email
  parse_head_elements :date_created, :date_modified, :with => Proc.new { |e| Time.parse(e) }

  @outlines = document_body ? initialize_outlines_from_document_body : []
end

Public Instance Methods

flatten() click to toggle source
# File lib/opml.rb, line 59
def flatten
  @flatten ||= @outlines.map(&:flatten).flatten
end

Private Instance Methods

define_head_attr_reader(attribute) click to toggle source
# File lib/opml.rb, line 72
def define_head_attr_reader(attribute)
  self.class.send(:attr_reader, attribute)
end
document_body() click to toggle source
# File lib/opml.rb, line 92
def document_body
  @document_body ||= @doc.elements['opml/body']
end
get_head_value(attribute) click to toggle source
# File lib/opml.rb, line 76
def get_head_value(attribute)
  if element = @doc.elements["opml/head/#{attribute.to_s.camelize(:lower)}"]
    element.text
  end
end
initialize_outlines_from_document_body() click to toggle source
# File lib/opml.rb, line 96
def initialize_outlines_from_document_body
  document_body.elements.map { |element| Outline.new(element) }
end
parse_head_elements(*elements) click to toggle source
# File lib/opml.rb, line 64
def parse_head_elements(*elements)
  options = elements.last.is_a?(Hash) ? elements.pop : {}
  elements.each do |attribute|
    define_head_attr_reader(attribute)
    set_head_value(attribute, options)
  end
end
parse_value(value, options) click to toggle source
# File lib/opml.rb, line 82
def parse_value(value, options)
  options[:with] ? options[:with].call(value) : value
end
set_head_value(attribute, options) click to toggle source
# File lib/opml.rb, line 86
def set_head_value(attribute, options)
  if value = get_head_value(attribute)
    instance_variable_set("@#{attribute}", parse_value(value, options))
  end
end