Class: Refinery::WordPress::Dump
- Inherits:
-
Object
- Object
- Refinery::WordPress::Dump
- Defined in:
- lib/wordpress/dump.rb
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
- #attachments ⇒ Object
- #authors ⇒ Object
- #categories ⇒ Object
-
#initialize(file_name) ⇒ Dump
constructor
A new instance of Dump.
- #pages(only_published = false) ⇒ Object
- #posts(only_published = false) ⇒ Object
- #tags ⇒ Object
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
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
4 5 6 |
# File 'lib/wordpress/dump.rb', line 4 def doc @doc end |
Instance Method Details
#attachments ⇒ Object
51 52 53 54 55 |
# File 'lib/wordpress/dump.rb', line 51 def doc.xpath("//item[wp:post_type = 'attachment']").collect do || Attachment.new() end end |
#authors ⇒ Object
16 17 18 19 20 |
# File 'lib/wordpress/dump.rb', line 16 def doc.xpath("//wp:author").collect do || Author.new() end end |
#categories ⇒ Object
45 46 47 48 49 |
# File 'lib/wordpress/dump.rb', line 45 def categories doc.xpath("//wp:category/wp:cat_name").collect do |category| Category.new(category.text) end end |
#pages(only_published = false) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/wordpress/dump.rb', line 22 def pages(only_published=false) pages = doc.xpath("//item[wp:post_type = 'page']").collect do |page| Page.new(page) end pages = pages.select(&:published?) if only_published pages end |