class WP2Middleman::PostCollection
Attributes
posts[R]
Public Class Methods
from_file(wp_xml_export_file)
click to toggle source
# File lib/wp2middleman/post_collection.rb, line 7 def self.from_file(wp_xml_export_file) xml = Nokogiri::XML(File.open("#{Dir.pwd}/#{wp_xml_export_file}")) new xml.css('item').collect { |raw_wp_post| WP2Middleman::Post.new(raw_wp_post) } end
new(posts=[])
click to toggle source
# File lib/wp2middleman/post_collection.rb, line 12 def initialize(posts=[]) @posts = posts end
Public Instance Methods
[](key)
click to toggle source
# File lib/wp2middleman/post_collection.rb, line 20 def [] key posts[key] end
each(&block)
click to toggle source
# File lib/wp2middleman/post_collection.rb, line 16 def each(&block) posts.each &block end
empty?()
click to toggle source
# File lib/wp2middleman/post_collection.rb, line 24 def empty? posts.empty? end
only_valid()
click to toggle source
# File lib/wp2middleman/post_collection.rb, line 32 def only_valid self.class.new(select(&:valid?)) end
to_middleman(body_to_markdown: false, include_fields: [])
click to toggle source
# File lib/wp2middleman/post_collection.rb, line 36 def to_middleman(body_to_markdown: false, include_fields: []) middleman_posts = collect { |p| WP2Middleman::MiddlemanPost.new(p, body_to_markdown: body_to_markdown, include_fields: include_fields) } self.class.new(middleman_posts) end
without_attachments()
click to toggle source
# File lib/wp2middleman/post_collection.rb, line 28 def without_attachments self.class.new(reject(&:attachment?)) end