Class: Origami::PDF::Header

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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_versionObject

Returns the value of attribute major_version.



34
35
36
# File 'lib/origami/header.rb', line 34

def major_version
  @major_version
end

#minor_versionObject

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
# File 'lib/origami/header.rb', line 45

def self.parse(stream) #:nodoc:
    unless stream.scan(MAGIC).nil?
        maj = stream['major'].to_i
        min = stream['minor'].to_i
    else
        raise InvalidHeaderError, "Invalid header format : #{stream.peek(15).inspect}"
    end

    stream.skip(REGEXP_WHITESPACES)

    PDF::Header.new(maj, min)
end

Instance Method Details

#to_fObject

:nodoc:



69
70
71
# File 'lib/origami/header.rb', line 69

def to_f #:nodoc:
    to_sym.to_s.to_f
end

#to_sObject

Outputs self into PDF code.



61
62
63
# File 'lib/origami/header.rb', line 61

def to_s
    "%PDF-#{@major_version}.#{@minor_version}".b + EOL
end

#to_symObject

:nodoc:



65
66
67
# File 'lib/origami/header.rb', line 65

def to_sym #:nodoc:
    "#{@major_version}.#{@minor_version}".to_sym
end