class ActiveXML::Collection::Route

Attributes

keys[R]

Public Class Methods

new(route, node) click to toggle source
# File lib/active_xml/collection/route.rb, line 6
def initialize(route, node)
  @route = "#{route.clone}"
  @keys = route_to_keys
  @node = node
  @cache = Hash.new
end

Public Instance Methods

generate() click to toggle source
# File lib/active_xml/collection/route.rb, line 17
def generate
  @keys.each do |key|
    @route.gsub!(":#{key}", read(key))
  end

  "#{@route}.xml"
end
to_hash() click to toggle source
# File lib/active_xml/collection/route.rb, line 13
def to_hash
  { read(@keys[0]) => [generate] }
end

Private Instance Methods

read(key) click to toggle source
# File lib/active_xml/collection/route.rb, line 27
def read(key)
  @cache[key] || (@cache[key] = @node.search(key.to_s).first.try(:content))
end
route_to_keys() click to toggle source
# File lib/active_xml/collection/route.rb, line 31
def route_to_keys
  @route.scan(/:[^\/]+/).map{|key| key.gsub(":", "").to_sym}
end