Class: OFX::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/ofx/version.rb

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ Version

Returns a new instance of Version.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ofx/version.rb', line 22

def initialize(version)
    @version = [0, 0, 0]

    return if version.nil?

    parts = case version
    when Version
      version.to_a
    when Integer
      [version, 0, 0]
    when Array
      version
    when /\./
      version.split(".")
    else
      [version[0..0], version[1..1], version[2..2]]
    end

    @version[0] = parts[0].to_i
    @version[1] = parts[1].to_i
    @version[2] = parts[2].to_i
end

Instance Method Details

#<=>(other) ⇒ Object



72
73
74
# File 'lib/ofx/version.rb', line 72

def <=> (other)
    @version <=> other.to_a
end

#empty?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/ofx/version.rb', line 68

def empty?
    @version == [0, 0, 0]
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
# File 'lib/ofx/version.rb', line 75

def eql?(other)
    other_a = other.to_a

    return @version[0] == other_a[0] && @version[1] == other_a[1] && @version[2] == other_a[2]
end

#hashObject



80
81
82
# File 'lib/ofx/version.rb', line 80

def hash()
    return @version.hash
end

#majorObject



45
46
47
# File 'lib/ofx/version.rb', line 45

def major
    @version[0]
end

#minorObject



49
50
51
# File 'lib/ofx/version.rb', line 49

def minor
    @version[1]
end

#revisionObject



53
54
55
# File 'lib/ofx/version.rb', line 53

def revision
    @version[2]
end

#to_aObject



64
65
66
# File 'lib/ofx/version.rb', line 64

def to_a
    @version.dup
end

#to_compact_sObject



60
61
62
# File 'lib/ofx/version.rb', line 60

def to_compact_s
    @version.join('')
end

#to_dotted_sObject



57
58
59
# File 'lib/ofx/version.rb', line 57

def to_dotted_s
    @version.join('.')
end