Class: Origami::FDF::Header

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

Constant Summary collapse

MAGIC =
/\A%FDF-(\d)\.(\d)/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(majorversion = 2, minorversion = 1) ⇒ Header

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

majorversion

Major version.

minorversion

Minor version.



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

def initialize(majorversion = 2, minorversion = 1)
  @majorversion, @minorversion = majorversion, minorversion
end

Instance Attribute Details

#majorversionObject

Returns the value of attribute majorversion.



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

def majorversion
  @majorversion
end

#minorversionObject

Returns the value of attribute minorversion.



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

def minorversion
  @minorversion
end

Class Method Details

.parse(stream) ⇒ Object

:nodoc:



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

def self.parse(stream) #:nodoc:
  
  if not stream.scan(MAGIC).nil?
    maj = stream[1].to_i
    min = stream[2].to_i
  else
    raise InvalidHeader, "Invalid header format"
  end
  
  FDF::Header.new(maj,min)
end

Instance Method Details

#to_fObject

:nodoc:



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

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

#to_sObject



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

def to_s
  "%FDF-#{@majorversion}.#{@minorversion}" + EOL
end

#to_symObject

:nodoc:



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

def to_sym #:nodoc:
  "#{@majorversion}.#{@minorversion}".to_sym
end