Class: BrandEins::Pages::Cover
- Inherits:
-
Object
- Object
- BrandEins::Pages::Cover
- Defined in:
- lib/brandeins/pages/cover.rb
Overview
Represents the magazine cover
Instance Method Summary collapse
- #cover_file_path_for_path(path) ⇒ Object
- #cover_image_url ⇒ Object
- #cover_title ⇒ Object
- #create_cover_pdf(image) ⇒ Object
- #download_cover_image ⇒ Object
- #fetcher ⇒ Object
- #file_name ⇒ Object
-
#initialize(magazine) ⇒ Cover
constructor
A new instance of Cover.
- #save_to(path) ⇒ Object
- #to_pdf ⇒ Object
Constructor Details
#initialize(magazine) ⇒ Cover
Returns a new instance of Cover.
13 14 15 |
# File 'lib/brandeins/pages/cover.rb', line 13 def initialize(magazine) @magazine = magazine end |
Instance Method Details
#cover_file_path_for_path(path) ⇒ Object
53 54 55 |
# File 'lib/brandeins/pages/cover.rb', line 53 def cover_file_path_for_path(path) Pathname.new(path) + file_name end |
#cover_image_url ⇒ Object
17 18 19 |
# File 'lib/brandeins/pages/cover.rb', line 17 def cover_image_url @magazine.cover_url end |
#cover_title ⇒ Object
21 22 23 |
# File 'lib/brandeins/pages/cover.rb', line 21 def cover_title @magazine.title end |
#create_cover_pdf(image) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/brandeins/pages/cover.rb', line 34 def create_cover_pdf(image) Prawn::Document.new do |pdf| pdf.text '<font size="18"><b>' + cover_title + '</b></font>', align: :center, inline_format: true if image # TODO: get Null Byte? # pdf.image image, position: :center, vposition: :center end end.render end |
#download_cover_image ⇒ Object
30 31 32 |
# File 'lib/brandeins/pages/cover.rb', line 30 def download_cover_image fetcher.fetch(cover_image_url) end |
#fetcher ⇒ Object
61 62 63 |
# File 'lib/brandeins/pages/cover.rb', line 61 def fetcher @fetcher ||= BrandEins::Utils::Fetcher.instance end |
#file_name ⇒ Object
57 58 59 |
# File 'lib/brandeins/pages/cover.rb', line 57 def file_name "magazine-cover-#{@magazine.month}-#{@magazine.year}.pdf" end |
#save_to(path) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/brandeins/pages/cover.rb', line 46 def save_to(path) cover_file_path = cover_file_path_for_path(path) return cover_file_path if File.exists? cover_file_path File.binwrite(cover_file_path, to_pdf) cover_file_path end |
#to_pdf ⇒ Object
25 26 27 28 |
# File 'lib/brandeins/pages/cover.rb', line 25 def to_pdf cover_image = download_cover_image create_cover_pdf(cover_image) end |