def sitemap_capture_segments(segment_mappings = {}, segments = [])
      values = {}

      # do nothing if there are no segments to work on
      if segments.kind_of?(Array)

        # first, look for mappings
        unless segment_mappings.blank?
          segments.each do |key|

            attribute_name = segment_mappings[key.to_sym].blank? ? key : segment_mappings[key.to_sym]

            if self.respond_to?(attribute_name)
              values[key] = self.send(attribute_name)
            end

          end
        end

        # second, look for attributes that have not already been found.
        segments.each do |key|

          unless values.has_key?(key)
            if self.respond_to?(key)
              values[key] = self.send(key)
            end
          end

        end

      end

      return values
    end
def sitemap_capture_segments(segment_mappings = {}, segments = [])
      values = {}

      # do nothing if there are no segments to work on
      if segments.kind_of?(Array)

        # first, look for mappings
        unless segment_mappings.blank?
          segments.each do |key|

            attribute_name = segment_mappings[key.to_sym].blank? ? key : segment_mappings[key.to_sym]

            if self.respond_to?(attribute_name)
              values[key] = self.send(attribute_name)
            end

          end
        end

        # second, look for attributes that have not already been found.
        segments.each do |key|

          unless values.has_key?(key)
            if self.respond_to?(key)
              values[key] = self.send(key)
            end
          end

        end

      end

      return values
    end
Segment keys are placeholders for the values that are plugged into a named route when it is constructed.

 The following Rails route has a two segment keys: :id and :format.

     book GET    /books/:id(.:format)   books#show

 :id is the row.id of a Book and :format is the extension to be used when constructing a path or url.

     book_path(1)                      #=> /book/1
     book_path(1, "html")              #=> /book/1.html
     book_path(id: 1, format: "html")  #=> /book/1.html
     book_path(id: 2, format: "xml")   #=> /book/2.xml

 sitemap_capture_segments attempts to populate a Hash with values associated with the required segment keys.

     row = Book.create(title: "Duck is a self-proclaimed resident moron...")
     puts row.id                                #=> 1
     row.sitemap_capture_segments(nil, [:id])   #=> {:id => 1}

 You have the ability to map attributes of an object to segment keys.  This could be useful for routes
 that do not follow standard convention or cases where you have some deeply nested resources.

     class BooksController < ApplicationController
       sitemap_segments :show, id: :my_id
     end

     class Book < ActiveRecord::Base
       attr_accessible :my_id, :author, :title

       before_save :generate_my_id

       def generate_my_id
         # do some magic
         self.my_id = 2
       end

     end

     row = Book.create(title: "Please ignore the first title :)")
     puts row.id                                #=> 1
     puts row.my_id                             #=> 2
     # normally, you would get the attributes via:
     # controller.sitemap_attributes("show")[:segments]
     attributes = {id: :my_id}
     row.sitemap_capture_segments(attributes, [:id])   #=> {:id => 2}

 Segment values are obtained in two stages.
 - Stage one asks the current object (controller or model) for attributes from segment_mappings and
   places those key/values in the returning hash.

 - Stage two asks the current object (controller or model) for attributes from segments array
   that have not already been found via segment_mappings and places those key/values in the returning hash.

 @param [Hash] segment_mappings    A Hash containing one-to-one attribute mappings for segment keys to object attributes.
 @param [Array] segments           The segments Array of a Rails Route.
 return [Hash]