Skip to content

Instantly share code, notes, and snippets.

@TheNotary
Created January 25, 2016 22:10
Show Gist options
  • Save TheNotary/514f1fb39637a520113b to your computer and use it in GitHub Desktop.
Save TheNotary/514f1fb39637a520113b to your computer and use it in GitHub Desktop.
require 'kindler'
require 'ostruct'
book = Kindler::Book.new title: "Cool Magazine"
book.mobi_type = :magzine
# articles = Article.all
a1 = OpenStruct.new({ "title" => "My Important News", "author" => "Max", "content" => "Bla bla bla bla bla", "section" => "News" })
a2 = OpenStruct.new({ "title" => "My Irrelivant News", "author" => "Max", "content" => "Bla bla bla bla bla", "section" => "News" })
a3 = OpenStruct.new({ "title" => "My Interesting Story", "author" => "Max", "content" => "Bla bla bla bla bla", "section" => "Stories" })
a4 = OpenStruct.new({ "title" => "My Boring Story that No One Wants to Hear", "author" => "Max", "content" => "Bla bla bla bla bla", "section" => "Stories" })
articles = [a1, a2, a3, a4]
articles.each do |article|
opts = {
title: article.title,
author: article.author,
content: article.content,
section: article.section
}
book.add_article(opts)
end
book.generate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment