Class: RedCard::Version

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

Instance Method Summary collapse

Constructor Details

#initialize(version, candidate) ⇒ Version

Returns a new instance of Version.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/redcard/version.rb', line 5

def initialize(version, candidate)
  @version_spec = version.to_str
  @version = convert @version_spec

  case candidate
  when Range
    @minimum_spec = candidate.begin.to_str
    @maximum_spec = candidate.end.to_str
    @exclusive = candidate.exclude_end?

    @minimum = convert @minimum_spec
    @maximum = convert @maximum_spec
  else
    @minimum = convert candidate.to_str
    @maximum = nil
    @exclusive = nil
  end
end

Instance Method Details

#convert(string) ⇒ Object



35
36
37
38
39
# File 'lib/redcard/version.rb', line 35

def convert(string)
  major, minor, tiny, patch = string.split "."
  parts = [major, minor, tiny, patch].map { |x| x.to_i }
  ("1%03d%03d%03d%05d" % parts).to_i
end

#valid?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
# File 'lib/redcard/version.rb', line 24

def valid?
  return false unless @version >= @minimum
  return true if @maximum.nil?

  if @exclusive
    return @version < @maximum
  else
    return @version <= @maximum
  end
end