Class: Vivlio::PDF::Metadata
- Inherits:
-
Object
- Object
- Vivlio::PDF::Metadata
- Defined in:
- lib/vivlio/pdf/metadata.rb
Overview
Values written into the PDF document information dictionary.
Constant Summary collapse
- FIELDS =
{ title: :Title, author: :Author, subject: :Subject, keywords: :Keywords, creator: :Creator, creation_date: :CreationDate }.freeze
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#creation_date ⇒ Object
readonly
Returns the value of attribute creation_date.
-
#creator ⇒ Object
readonly
Returns the value of attribute creator.
-
#keywords ⇒ Object
readonly
Returns the value of attribute keywords.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
-
.coerce(value) ⇒ Object
Accepts a Metadata, a Hash of the fields above, or nil.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
True when there is nothing to write, i.e.
-
#initialize(title: nil, author: nil, subject: nil, keywords: nil, creator: nil, creation_date: nil) ⇒ Metadata
constructor
A new instance of Metadata.
- #to_h ⇒ Object
-
#with_creator(creator) ⇒ Object
Names what produced the PDF, unless the caller named it themselves.
-
#write_to(info) ⇒ Object
infois a HexaPDF document information dictionary.
Constructor Details
#initialize(title: nil, author: nil, subject: nil, keywords: nil, creator: nil, creation_date: nil) ⇒ Metadata
Returns a new instance of Metadata.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/vivlio/pdf/metadata.rb', line 23 def initialize(title: nil, author: nil, subject: nil, keywords: nil, creator: nil, creation_date: nil) @title = title @author = @subject = subject @keywords = keywords @creator = creator @creation_date = creation_date freeze end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
11 12 13 |
# File 'lib/vivlio/pdf/metadata.rb', line 11 def @author end |
#creation_date ⇒ Object (readonly)
Returns the value of attribute creation_date.
11 12 13 |
# File 'lib/vivlio/pdf/metadata.rb', line 11 def creation_date @creation_date end |
#creator ⇒ Object (readonly)
Returns the value of attribute creator.
11 12 13 |
# File 'lib/vivlio/pdf/metadata.rb', line 11 def creator @creator end |
#keywords ⇒ Object (readonly)
Returns the value of attribute keywords.
11 12 13 |
# File 'lib/vivlio/pdf/metadata.rb', line 11 def keywords @keywords end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
11 12 13 |
# File 'lib/vivlio/pdf/metadata.rb', line 11 def subject @subject end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
11 12 13 |
# File 'lib/vivlio/pdf/metadata.rb', line 11 def title @title end |
Class Method Details
.coerce(value) ⇒ Object
Accepts a Metadata, a Hash of the fields above, or nil.
14 15 16 17 18 19 20 21 |
# File 'lib/vivlio/pdf/metadata.rb', line 14 def self.coerce(value) case value when Metadata then value when nil then new when Hash then new(**value) else raise ArgumentError, "cannot coerce #{value.class} into Metadata" end end |
Instance Method Details
#empty? ⇒ Boolean
True when there is nothing to write, i.e. no reason to rewrite the PDF for metadata alone.
40 41 42 |
# File 'lib/vivlio/pdf/metadata.rb', line 40 def empty? to_h.empty? end |
#to_h ⇒ Object
34 35 36 |
# File 'lib/vivlio/pdf/metadata.rb', line 34 def to_h FIELDS.keys.to_h { |name| [name, public_send(name)] }.compact end |
#with_creator(creator) ⇒ Object
Names what produced the PDF, unless the caller named it themselves. Deciding that string is Printer's job: only it knows which viewer actually did the rendering.
47 48 49 50 51 |
# File 'lib/vivlio/pdf/metadata.rb', line 47 def with_creator(creator) return self if @creator Metadata.new(**to_h, creator: creator) end |
#write_to(info) ⇒ Object
info is a HexaPDF document information dictionary.
54 55 56 57 58 59 60 |
# File 'lib/vivlio/pdf/metadata.rb', line 54 def write_to(info) FIELDS.each do |name, key| value = public_send(name) info[key] = value if value end info end |