Class: Atom::CoreElement
Instance Attribute Summary
Attributes inherited from Element
#elem
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Element
#add, element_attr_accessor, element_attr_accessors, element_datetime_accessor, element_datetime_accessors, element_name, element_ns, element_object_list_accessor, element_text_accessor, element_text_accessors, element_text_list_accessor, #get, #get_attr, #get_object, #get_objects, #getlist, new, ns, #set, #set_attr, #to_s
Constructor Details
#initialize(params = {}) ⇒ CoreElement
Returns a new instance of CoreElement.
903
904
905
906
907
908
909
910
911
|
# File 'lib/atomutil.rb', line 903
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
|
Class Method Details
.element_link_accessor(type) ⇒ Object
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
|
# File 'lib/atomutil.rb', line 846
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) ⇒ Object
875
876
877
|
# File 'lib/atomutil.rb', line 875
def self.element_link_accessors(*types)
types.flatten.each{ |type| element_link_accessor(type) }
end
|
Instance Method Details
#add_alternate_link(href) ⇒ Object
890
891
892
893
894
895
|
# File 'lib/atomutil.rb', line 890
def add_alternate_link(href)
l = Link.new
l.href = href
l.rel = 'alternate'
add_link l
end
|
#alternate_link ⇒ Object
885
886
887
888
|
# File 'lib/atomutil.rb', line 885
def alternate_link
alternates = links.select{ |l| l.rel.nil? || l.rel == 'alternate' }
alternates.empty? ? nil : alternates.first.href
end
|
#alternate_link=(href) ⇒ Object
897
898
899
900
901
|
# File 'lib/atomutil.rb', line 897
def alternate_link=(href)
xpath = child_xpath(Namespace::ATOM, 'link', { :rel => 'alternate' })
@elem.elements.delete_all(xpath)
add_alternate_link(href)
end
|
#alternate_links ⇒ Object
881
882
883
|
# File 'lib/atomutil.rb', line 881
def alternate_links
links.select{ |l| l.rel.nil? || l.rel == 'alternate' }.collect{ |l| l.href }
end
|