class Atom::CoreElement
Public Class Methods
element_link_accessor(type)
click to toggle source
# File lib/atomutil.rb, line 849 def self.element_link_accessor(type) type = type.to_s meth_name = [type.tr('-','_'), 'link'].join('_') class_eval(<<-EOS, __FILE__, __LINE__) def #{meth_name} selected = links.select{ |l| l.rel == '#{type}' } selected.empty? ? nil : selected.first.href end def #{meth_name}s links.select{ |l| l.rel == '#{type}' }.collect{ |l| l.href } end def add_#{meth_name}(href) l = Link.new l.href = href l.rel = '#{type}' add_link l end def #{meth_name}=(href) xpath = child_xpath(Namespace::ATOM, 'link', { :rel => '#{type}' }) @elem.elements.delete_all(xpath) add_#{meth_name}(href) end EOS end
element_link_accessors(*types)
click to toggle source
# File lib/atomutil.rb, line 878 def self.element_link_accessors(*types) types.flatten.each{ |type| element_link_accessor(type) } end
new(params={})
click to toggle source
Calls superclass method
Atom::RootElement::new
# File lib/atomutil.rb, line 906 def initialize(params={}) if params.has_key?(:uri) || params.has_key?(:file) target = params.has_key?(:uri) ? URI.parse(params.delete(:uri)) \ : params[:file].is_a?(Pathname) ? params.delete(:file) \ : Pathname.new(params.delete(:file)) params[:stream] = target.open { |f| f.read } end super(params) end
Public Instance Methods
add_alternate_link(href)
click to toggle source
# File lib/atomutil.rb, line 893 def add_alternate_link(href) l = Link.new l.href = href l.rel = 'alternate' add_link l end
alternate_link()
click to toggle source
# File lib/atomutil.rb, line 888 def alternate_link alternates = links.select{ |l| l.rel.nil? || l.rel == 'alternate' } alternates.empty? ? nil : alternates.first.href end
alternate_link=(href)
click to toggle source
# File lib/atomutil.rb, line 900 def alternate_link=(href) xpath = child_xpath(Namespace::ATOM, 'link', { :rel => 'alternate' }) @elem.elements.delete_all(xpath) add_alternate_link(href) end
alternate_links()
click to toggle source
# File lib/atomutil.rb, line 884 def alternate_links links.select{ |l| l.rel.nil? || l.rel == 'alternate' }.collect{ |l| l.href } end