Class: Wordpress::WXR::Attachments

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/wordpress/wxr/attachments.rb

Instance Method Summary collapse

Constructor Details

#initialize(document, wxr) ⇒ Attachments

Returns a new instance of Attachments.



11
12
13
14
# File 'lib/wordpress/wxr/attachments.rb', line 11

def initialize(document, wxr)
  @document = document
  @wxr = wxr
end

Instance Method Details

#eachObject



16
17
18
19
20
21
22
# File 'lib/wordpress/wxr/attachments.rb', line 16

def each
  return enum_for(:each) unless block_given?

  nodes.each do |node|
    yield Attachment.new(node, wxr)
  end
end

#find_by(id:) ⇒ Object



24
25
26
27
28
29
# File 'lib/wordpress/wxr/attachments.rb', line 24

def find_by(id:)
  attachment = nodes.xpath("wp:post_id[text() = '#{Integer(id)}']/parent::node()")
  return unless attachment

  Attachment.new(attachment, wxr)
end