Class: Orchid::Version

Inherits:
Object
  • Object
show all
Defined in:
lib/orchid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value = nil) ⇒ Version

Returns a new instance of Version.



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/orchid.rb', line 38

def initialize(value = nil)
  if value.class == String
    value = value.split '.'
  elsif value.class == Hash
    value = [value[:major], value[:minor], value[:micro]]
  elsif value.nil?
    value = [nil, 0, 0]
  end
  
  @major = value.first ? value.first.to_i : nil
  @minor = value[1] ? value[1].to_i : 0
  @micro = value.last ? value.last.to_i : 0
end

Instance Attribute Details

#majorObject

Returns the value of attribute major.



36
37
38
# File 'lib/orchid.rb', line 36

def major
  @major
end

#microObject

Returns the value of attribute micro.



36
37
38
# File 'lib/orchid.rb', line 36

def micro
  @micro
end

#minorObject

Returns the value of attribute minor.



36
37
38
# File 'lib/orchid.rb', line 36

def minor
  @minor
end

Instance Method Details

#to_aObject



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

def to_a
  return [@major, @minor, @micro]
end

#to_hObject



56
57
58
# File 'lib/orchid.rb', line 56

def to_h
  return {:major => @major, :minor => @minor, :micro => @micro}
end

#to_sObject



52
53
54
# File 'lib/orchid.rb', line 52

def to_s
  return "#{@major}.#{@minor}.#{@micro}"
end