Class: Oos4ruby::Entry
- Inherits:
-
Object
- Object
- Oos4ruby::Entry
- Defined in:
- lib/oos4ruby/entry.rb
Instance Method Summary collapse
- #add_category(term, scheme = nil, label = nil) ⇒ Object
- #add_child(name, prefix = nil, namespace = nil, attr = {}) ⇒ Object
- #category(cat) ⇒ Object
- #child(field, namespace = nil) ⇒ Object
- #delete_category(c) ⇒ Object
- #first(xp) ⇒ Object
-
#initialize(node) ⇒ Entry
constructor
A new instance of Entry.
- #link(rel) ⇒ Object
- #match(xp) ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Method Details
#add_category(term, scheme = nil, label = nil) ⇒ Object
61 62 63 64 |
# File 'lib/oos4ruby/entry.rb', line 61 def add_category(term, scheme = nil, label = nil) c = @element.add_category(term, scheme, label) c end |
#add_child(name, prefix = nil, namespace = nil, attr = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/oos4ruby/entry.rb', line 32 def add_child(name, prefix = nil, namespace = nil, attr = {}) name = (prefix || 'atom') + ':' + name e = REXML::Element.new( name, @element ) if prefix && namespace e.add_namespace(prefix, namespace) else e.add_namespace('atom', AtomNamespace) end if !attr.empty? attr.each_pair { |key, value| e.add_attribute(key.to_s, value) } end e end |
#category(cat) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/oos4ruby/entry.rb', line 46 def category( cat ) first = true xpath = "./atom:category[" if cat[:term] xpath += "@term=\"#{cat[:term]}\"" first = false end xpath += " and " unless first if cat[:scheme] xpath += "@scheme=\"#{cat[:scheme]}\"" end xpath += "]" REXML::XPath.first(@element, xpath, XmlNamespaces) end |
#child(field, namespace = nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/oos4ruby/entry.rb', line 20 def child(field, namespace = nil) if (namespace) thisNS = {} prefix = 'NS' thisNS[prefix] = namespace else prefix = 'atom' thisNS = XmlNamespaces end return REXML::XPath.first(@element, "./#{prefix}:#{field}", thisNS) end |
#delete_category(c) ⇒ Object
66 67 68 |
# File 'lib/oos4ruby/entry.rb', line 66 def delete_category(c) @element.delete_element c end |
#first(xp) ⇒ Object
86 87 88 |
# File 'lib/oos4ruby/entry.rb', line 86 def first(xp) REXML::XPath.first(@element, xp, XmlNamespaces) end |
#link(rel) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/oos4ruby/entry.rb', line 70 def link(rel) a = REXML::XPath.first(@element, "./atom:link[@rel=\"#{rel}\"]", XmlNamespaces) if a uri = URI.parse a.attributes['href'] if uri.absolute? return uri else return URI.parse(OOS_URL).merge(uri) end end end |
#match(xp) ⇒ Object
82 83 84 |
# File 'lib/oos4ruby/entry.rb', line 82 def match(xp) REXML::XPath.match(@element, xp, XmlNamespaces) end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/oos4ruby/entry.rb', line 16 def to_s "<?xml version='1.0' ?>\n" + @element.to_s end |