Class: Jim::VersionParser

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

Constant Summary collapse

NOT_EXTENSIONS =
%w{.min .pre .beta}

Class Method Summary collapse

Class Method Details

.parse_filename(filename) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/jim/version_parser.rb', line 6

def self.parse_filename(filename)
  f = Pathname.new(filename).basename.to_s
  extension = f.scan(/\.[^\.\d\s\-\_][^\.]*$/)[0]
  if NOT_EXTENSIONS.include?(extension)
    extension = nil
  else
    f.gsub!(/#{extension}$/, '')
  end

  name, after_name, delimiter, version = f.scan(/^([a-z\.\-\_]+)(([\.\-\_\s])v?(([\w\d]{7})|(\d[\d\w\.]*)))?$/i)[0]
  [name || f, version || "0"]
end

.parse_package_json(package) ⇒ Object



19
20
21
22
# File 'lib/jim/version_parser.rb', line 19

def self.parse_package_json(package)
  json = Yajl::Parser.parse(package)
  [json["name"], json["version"]]
end