Class: Origami::FDF::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/origami/extensions/fdf.rb

Constant Summary collapse

MAGIC =
/%FDF-(?<major>\d)\.(?<minor>\d)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(major_version = 1, minor_version = 2) ⇒ Header

Creates a file header, with the given major and minor versions.

major_version

Major version.

minor_version

Minor version.



57
58
59
# File 'lib/origami/extensions/fdf.rb', line 57

def initialize(major_version = 1, minor_version = 2)
    @major_version, @minor_version = major_version, minor_version
end

Instance Attribute Details

#major_versionObject

Returns the value of attribute major_version.



50
51
52
# File 'lib/origami/extensions/fdf.rb', line 50

def major_version
  @major_version
end

#minor_versionObject

Returns the value of attribute minor_version.



50
51
52
# File 'lib/origami/extensions/fdf.rb', line 50

def minor_version
  @minor_version
end

Class Method Details

.parse(stream) ⇒ Object

:nodoc:



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/origami/extensions/fdf.rb', line 61

def self.parse(stream) #:nodoc:
    scanner = Parser.init_scanner(stream)

    if not scanner.scan(MAGIC).nil?
        maj = scanner['major'].to_i
        min = scanner['minor'].to_i
    else
        raise InvalidHeader, "Invalid header format"
    end

    scanner.skip(REGEXP_WHITESPACES)

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

Instance Method Details

#to_fObject

:nodoc:



84
85
86
# File 'lib/origami/extensions/fdf.rb', line 84

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

#to_s(eol: $/) ⇒ Object



76
77
78
# File 'lib/origami/extensions/fdf.rb', line 76

def to_s(eol: $/)
    "%FDF-#{@major_version}.#{@minor_version}".b + eol
end

#to_symObject

:nodoc:



80
81
82
# File 'lib/origami/extensions/fdf.rb', line 80

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