Class: WP2Middleman::PostCollection
- Inherits:
-
Object
- Object
- WP2Middleman::PostCollection
- Includes:
- Enumerable
- Defined in:
- lib/wp2middleman/post_collection.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(posts = []) ⇒ PostCollection
constructor
A new instance of PostCollection.
- #only_valid ⇒ Object
- #to_middleman(body_to_markdown: false, include_fields: []) ⇒ Object
- #without_attachments ⇒ Object
Constructor Details
#initialize(posts = []) ⇒ PostCollection
Returns a new instance of PostCollection.
12 13 14 |
# File 'lib/wp2middleman/post_collection.rb', line 12 def initialize(posts=[]) @posts = posts end |
Class Method Details
.from_file(wp_xml_export_file) ⇒ Object
7 8 9 10 |
# 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 |
Instance Method Details
#[](key) ⇒ Object
20 21 22 |
# File 'lib/wp2middleman/post_collection.rb', line 20 def [] key posts[key] end |
#each(&block) ⇒ Object
16 17 18 |
# File 'lib/wp2middleman/post_collection.rb', line 16 def each(&block) posts.each &block end |
#empty? ⇒ Boolean
24 25 26 |
# File 'lib/wp2middleman/post_collection.rb', line 24 def empty? posts.empty? end |
#only_valid ⇒ Object
32 33 34 |
# 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: []) ⇒ Object
36 37 38 39 |
# 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 ⇒ Object
28 29 30 |
# File 'lib/wp2middleman/post_collection.rb', line 28 def self.class.new(reject(&:attachment?)) end |