Class: Refinery::WordPress::Dump

Inherits:
Object
  • Object
show all
Defined in:
lib/wordpress/dump.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_name) ⇒ Dump

Returns a new instance of Dump.



6
7
8
9
10
11
12
13
14
# File 'lib/wordpress/dump.rb', line 6

def initialize(file_name)
  file_name = File.absolute_path(file_name)

  raise "Given file '#{file_name}' no file or not readable." \
    unless File.file?(file_name) && File.readable?(file_name)
  
  file = File.open(file_name)
  @doc = Nokogiri::XML(file)
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



4
5
6
# File 'lib/wordpress/dump.rb', line 4

def doc
  @doc
end

Instance Method Details

#authorsObject



16
17
18
19
20
# File 'lib/wordpress/dump.rb', line 16

def authors
  doc.xpath("//wp:author").collect do |author|
    Author.new(author)
  end
end

#categoriesObject



42
43
44
45
46
# File 'lib/wordpress/dump.rb', line 42

def categories
  doc.xpath("//wp:category/wp:cat_name").collect do |category|
    Category.new(category.text)
  end
end

#pagesObject



22
23
24
25
26
# File 'lib/wordpress/dump.rb', line 22

def pages
  doc.xpath("//item[wp:post_type = 'page']").collect do |page|
    Page.new(page)
  end
end

#posts(only_published = false) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/wordpress/dump.rb', line 28

def posts(only_published=false)
  posts = doc.xpath("//item[wp:post_type = 'post']").collect do |post|
    Post.new(post)
  end
  posts = posts.select(&:published?) if only_published
  posts
end

#tagsObject



36
37
38
39
40
# File 'lib/wordpress/dump.rb', line 36

def tags
  doc.xpath("//wp:tag/wp:tag_slug").collect do |tag|
    Tag.new(tag.text)
  end
end