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
# File 'lib/origami/extensions/fdf.rb', line 61

def self.parse(stream) #:nodoc:
    if not stream.scan(MAGIC).nil?
        maj = stream['major'].to_i
        min = stream['minor'].to_i
    else
        raise InvalidHeader, "Invalid header format"
    end

    stream.skip(REGEXP_WHITESPACES)

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

Instance Method Details

#to_fObject

:nodoc:


82
83
84
# File 'lib/origami/extensions/fdf.rb', line 82

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

#to_sObject


74
75
76
# File 'lib/origami/extensions/fdf.rb', line 74

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

#to_symObject

:nodoc:


78
79
80
# File 'lib/origami/extensions/fdf.rb', line 78

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