Class: Origami::PDF::Header
- Inherits:
-
Object
- Object
- Origami::PDF::Header
- Defined in:
- lib/origami/header.rb
Overview
Class representing a PDF Header.
Constant Summary collapse
- MAGIC =
/%PDF-(?<major>\d+)\.(?<minor>\d+)/
Instance Attribute Summary collapse
-
#major_version ⇒ Object
Returns the value of attribute major_version.
-
#minor_version ⇒ Object
Returns the value of attribute minor_version.
Class Method Summary collapse
-
.parse(stream) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#initialize(major_version = 1, minor_version = 4) ⇒ Header
constructor
Creates a file header, with the given major and minor versions.
-
#to_s(eol: $/) ⇒ Object
Outputs self into PDF code.
-
#version ⇒ Object
Returns the Header version as a String.
Constructor Details
#initialize(major_version = 1, minor_version = 4) ⇒ Header
Creates a file header, with the given major and minor versions.
- major_version
-
Major PDF version, must be 1.
- minor_version
-
Minor PDF version, must be between 0 and 7.
39 40 41 |
# File 'lib/origami/header.rb', line 39 def initialize(major_version = 1, minor_version = 4) @major_version, @minor_version = major_version, minor_version end |
Instance Attribute Details
#major_version ⇒ Object
Returns the value of attribute major_version.
32 33 34 |
# File 'lib/origami/header.rb', line 32 def major_version @major_version end |
#minor_version ⇒ Object
Returns the value of attribute minor_version.
32 33 34 |
# File 'lib/origami/header.rb', line 32 def minor_version @minor_version end |
Class Method Details
.parse(stream) ⇒ Object
:nodoc:
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/origami/header.rb', line 43 def self.parse(stream) # :nodoc: scanner = Parser.init_scanner(stream) if scanner.scan(MAGIC).nil? raise InvalidHeaderError, "Invalid header format : #{scanner.peek(15).inspect}" else maj = scanner['major'].to_i min = scanner['minor'].to_i end scanner.skip(REGEXP_WHITESPACES) PDF::Header.new(maj, min) end |
Instance Method Details
#to_s(eol: $/) ⇒ Object
Outputs self into PDF code.
68 69 70 |
# File 'lib/origami/header.rb', line 68 def to_s(eol: $/) "%PDF-#{version}".b + eol end |
#version ⇒ Object
Returns the Header version as a String.
61 62 63 |
# File 'lib/origami/header.rb', line 61 def version "#{@major_version}.#{@minor_version}" end |