Class: Pik::VersionParser

Inherits:
Object show all
Defined in:
lib/pik/version_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version) ⇒ VersionParser

Returns a new instance of VersionParser.



9
10
11
12
# File 'lib/pik/version_parser.rb', line 9

def initialize(version)
  @version = version
  @parts = @version.split(/ |\(|\)/).reject{|i| i.empty? }
end

Class Method Details

.parse(version) ⇒ Object



5
6
7
# File 'lib/pik/version_parser.rb', line 5

def self.parse(version)
  new(version)
end

Instance Method Details

#dateObject



23
24
25
26
27
28
29
30
31
# File 'lib/pik/version_parser.rb', line 23

def date
  case interpreter
  when 'IronRuby'
    nil
  when 'ruby', 'jruby'
    md = @version.match(/\d\d\d\d\-\d\d\-\d\d/)
    md[0] if md
  end
end

#full_versionObject



41
42
43
# File 'lib/pik/version_parser.rb', line 41

def full_version
  match(/.+: (.+)/)
end

#interpreterObject



14
15
16
# File 'lib/pik/version_parser.rb', line 14

def interpreter
  @interpreter ||= @parts[1]
end

#match(re) ⇒ Object



45
46
47
48
# File 'lib/pik/version_parser.rb', line 45

def match(re)
  md = @version.match(re) 
  md.captures.compact[-1] if md
end

#patchlevelObject



37
38
39
# File 'lib/pik/version_parser.rb', line 37

def patchlevel
  match(/patchlevel (\d+)|\dp(\d+)/) 
end

#platformObject



33
34
35
# File 'lib/pik/version_parser.rb', line 33

def platform
  match(/\[(.+)\]|(\.NET.+)/) 
end

#versionObject



18
19
20
21
# File 'lib/pik/version_parser.rb', line 18

def version
  md = @parts[2].match(/\d\.\d\.\d\.\d|\d\.\d\.\d/)
  md[0] if md
end