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.
41 42 43 |
# File 'lib/origami/header.rb', line 41 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.
34 35 36 |
# File 'lib/origami/header.rb', line 34 def major_version @major_version end |
#minor_version ⇒ Object
Returns the value of attribute minor_version.
34 35 36 |
# File 'lib/origami/header.rb', line 34 def minor_version @minor_version end |
Class Method Details
.parse(stream) ⇒ Object
:nodoc:
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/origami/header.rb', line 45 def self.parse(stream) #:nodoc: scanner = Parser.init_scanner(stream) unless scanner.scan(MAGIC).nil? maj = scanner['major'].to_i min = scanner['minor'].to_i else raise InvalidHeaderError, "Invalid header format : #{scanner.peek(15).inspect}" end scanner.skip(REGEXP_WHITESPACES) PDF::Header.new(maj, min) end |
Instance Method Details
#to_s(eol: $/) ⇒ Object
Outputs self into PDF code.
70 71 72 |
# File 'lib/origami/header.rb', line 70 def to_s(eol: $/) "%PDF-#{self.version}".b + eol end |
#version ⇒ Object
Returns the Header version as a String.
63 64 65 |
# File 'lib/origami/header.rb', line 63 def version "#{@major_version}.#{@minor_version}" end |