Class: WpxmlParser::Blog

Inherits:
Object
  • Object
show all
Defined in:
lib/wpxml_parser/blog.rb

Instance Method Summary collapse

Constructor Details

#initialize(xml_filename) ⇒ Blog

Returns a new instance of Blog.



6
7
8
9
10
# File 'lib/wpxml_parser/blog.rb', line 6

def initialize(xml_filename)
  File.open(xml_filename) do |xml_file|
    @xml = Nokogiri::XML(xml_file)
  end
end

Instance Method Details

#attachmentsObject



22
23
24
25
26
# File 'lib/wpxml_parser/blog.rb', line 22

def attachments
  @xml.xpath('//item').map do |item|
    Post.new(item)
  end.select{|p| p.post_type == 'attachment'}
end

#find_post(post_id) ⇒ Object



18
19
20
# File 'lib/wpxml_parser/blog.rb', line 18

def find_post(post_id)
  posts.find{|p| p.post_id == post_id}
end

#postsObject



12
13
14
15
16
# File 'lib/wpxml_parser/blog.rb', line 12

def posts
  @xml.xpath('//item').map do |item|
    Post.new(item)
  end.select{|p| p.post_type == 'post' && p.status == 'publish'}
end