Class: Wordpress::WXR::Categories

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

Instance Method Summary collapse

Constructor Details

#initialize(document, wxr) ⇒ Categories

Returns a new instance of Categories.



11
12
13
14
# File 'lib/wordpress/wxr/categories.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/categories.rb', line 16

def each
  return enum_for(:each) unless block_given?

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

#find_by(nicename:) ⇒ Object



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

def find_by(nicename:)
  return if nicename.empty?

  category = nodes.xpath("wp:category_nicename[text() = '#{nicename}']/parent::node()")
  return unless category

  Category.new(category, wxr)
end