Class: Atom::Source

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Xml::Parseable
Defined in:
lib/atom.rb

Overview

Represents a Source as defined by the Atom Syndication Format specification.

See also www.atomenabled.org/developers/syndication/atom-format-spec.php#element.source

Instance Method Summary collapse

Methods included from Xml::Parseable

#==, #current_node_is?, included, #next_node_is?, #parse, #to_xml

Constructor Details

#initialize(o = {}) {|_self| ... } ⇒ Source

Returns a new instance of Source.

Yields:

  • (_self)

Yield Parameters:

  • _self (Atom::Source)

    the object that the method was called on



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'lib/atom.rb', line 343

def initialize(o = {})
  @authors, @contributors, @links = [], [], Links.new

  case o
  when XML::Reader
    unless current_node_is?(o, 'source', NAMESPACE)
      raise ArgumentError, "Invalid node for atom:source - #{o.name}(#{o.namespace})"
    end

    o.read
    parse(o)
  when Hash
    o.each do |k, v|
      self.send("#{k.to_s}=", v)
    end
  else
    raise ArgumentError, "Got #{o.class} but expected a Hash or XML::Reader"
  end
  
  yield(self) if block_given?   
end