class OpmlJanitor::Outline

Attributes

hash[R]

Public Class Methods

new(node) click to toggle source
# File lib/opml_janitor/outline.rb, line 7
def initialize(node)
  @node = node
  @hash = {}
end

Public Instance Methods

to_hash() click to toggle source
# File lib/opml_janitor/outline.rb, line 12
def to_hash
  @node.attributes.each do |attribute|
    key = underscore(attribute[0]).to_sym
    @hash[key] = @node.attr(attribute[0])
  end
  @hash
end

Private Instance Methods

underscore(camel_cased_word) click to toggle source

from ActiveSupport

# File lib/opml_janitor/outline.rb, line 23
def underscore(camel_cased_word)
  word = camel_cased_word.to_s.dup
  word.gsub!(/::/, '/')
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
  word.tr!("-", "_")
  word.downcase!
  word
end