Class: Drupid::VersionCore

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/drupid/project_version.rb

Overview

Represents the core attribute of a version object (e.g., ‘7.x’). A VersionCore object can be initialized from a number, a string, a Drupid::VersionCore object or a Drupid::Version object.

Examples:

core = Drupid::VersionCore.new '8.x'
core = Drupid::VersionCore.new '8'
core = Drupid::VersionCore.new '8.x-1.0'
core = Drupid::VersionCore.new 8
core = Drupid::VersionCore.new(Drupid::Version.new(8, '1.0'))

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(spec) ⇒ VersionCore

Returns a new instance of VersionCore.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/drupid/project_version.rb', line 43

def initialize spec
  if spec.is_a?(String)
    spec.strip.match(/^(\d+)(\.x)?($|-)/)
    raise NotDrupalVersionError, "Wrong core specification: #{core}" unless $1
    @core = $1.to_i
  elsif spec.is_a?(Version)
    @core = spec.core.to_i
  elsif spec.is_a?(VersionCore)
    @core = spec.to_i
  elsif spec.is_a?(Numeric)
    @core = spec.to_i # to_i truncates a Float object (so that 7.9 correctly becomes 7)
  else
    raise NotDrupalVersionError, "Wrong core specification: #{core}"
  end
end

Instance Attribute Details

#coreObject (readonly)

Returns the value of attribute core.



41
42
43
# File 'lib/drupid/project_version.rb', line 41

def core
  @core
end

Instance Method Details

#<=>(other) ⇒ Object



69
70
71
# File 'lib/drupid/project_version.rb', line 69

def <=>(other)
  @core <=> other.core
end

#to_iObject

Returns the core number as a Fixnum object.



65
66
67
# File 'lib/drupid/project_version.rb', line 65

def to_i
  @core
end

#to_sObject

Returns the core number as a string, e.g., ‘8.x’.



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

def to_s
  @core.to_s + '.x'
end