fv 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea4f3128576facd4f6f97a40534cb0995d304a37
4
+ data.tar.gz: a3f02307c1f72b3fe93be704e55450e94bcd9aac
5
+ SHA512:
6
+ metadata.gz: e6375f92457199902d53a8e93a07e9d6c56ae3562cc08a8cd28c269b85fb7f57a02ffeba82f072e51116010320f5f354b0150485ac6e7f3da00a05ac7f9409eb
7
+ data.tar.gz: 5cde11973ab9d79660ed53fd26e7f0cfb32b598a404dd110c5024d943b7cf79f64cd6e312995ed1f00d5bc25cdfca2c852bbbb78cd356f03017124bac333c2fa
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,9 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.0
5
+ - 2.1
6
+ - 2.2
7
+ - 2.3.1
8
+ - jruby-9.0.0.0
9
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fv.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Alex Tonkonozhenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,60 @@
1
+ # Fv [![Build Status](https://travis-ci.org/Tonkonozhenko/fv.svg?branch=master)](https://travis-ci.org/Tonkonozhenko/fv)
2
+
3
+ Fv is gem for fast operations with version numbers
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'fv'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install fv
20
+
21
+ ## Usage
22
+
23
+ Comparing versions became as easy as never. It takes only `4 chars` more than comparing strings.
24
+
25
+ ```ruby
26
+
27
+ require 'fv/all'
28
+ #=> true
29
+
30
+ v1 = '1.12.0'
31
+ #=> "1.12.0"
32
+ v2 = '1.2.0'
33
+ #=> "1.2.0"
34
+
35
+ v1 > v2
36
+ #=> false
37
+ Fv(v1) > v2
38
+ #=> true
39
+
40
+
41
+ ```
42
+
43
+ ## Development
44
+
45
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `rake spec` to run the tests.
46
+
47
+ To install this gem onto your local machine, run `bundle exec rake install`.
48
+
49
+ <!-- Comment for releasing: -->
50
+ <!-- To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). -->
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tonkonozhenko/fv.
55
+
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
60
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fv/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fv"
8
+ spec.version = Fv::VERSION
9
+ spec.authors = ["Alex Tonkonozhenko"]
10
+ spec.email = ["tonkonozhenko@gmail.com"]
11
+
12
+ spec.summary = %q{Fv is gem for fast operations with version numbers}
13
+ spec.homepage = "https://github.com/tonkonozhenko/fv"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
@@ -0,0 +1,9 @@
1
+ require 'fv/version'
2
+ require 'fv/v'
3
+ require 'fv/parser'
4
+
5
+ module Fv
6
+ def self.parse(version)
7
+ Parser.parse(version)
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'fv'
2
+ require 'fv/core_ext'
@@ -0,0 +1 @@
1
+ require 'fv/core_ext/object'
@@ -0,0 +1,3 @@
1
+ def Fv(version)
2
+ Fv.parse(version)
3
+ end
@@ -0,0 +1,46 @@
1
+ module Fv
2
+ class Parser
3
+ PART_REGEXP = /\A([0-9A-Za-z-]+\.)*[0-9A-Za-z-]+\z/
4
+
5
+ class << self
6
+ def parse(version)
7
+ return version if version.is_a?(V)
8
+
9
+ normalized_version = version.to_s.split('+').first # Remove metadata
10
+
11
+ major, minor, patch = normalized_version.split('.', 3)
12
+
13
+ major = validate_part major, name: 'major'
14
+ minor = validate_part minor, name: 'minor'
15
+ patch = validate_part patch, name: 'patch', only_integer: false
16
+
17
+ V.new(major, minor, patch)
18
+ end
19
+
20
+ private
21
+ def validate_part(part, name: nil, only_integer: true, non_negative: true)
22
+ name = name.capitalize
23
+ is_integer = true
24
+
25
+ part = begin
26
+ Integer(part)
27
+ rescue ArgumentError => e
28
+ raise unless e.message =~ /invalid value for Integer/
29
+ raise WrongVersionError, "#{name} version must be integer" if only_integer
30
+ is_integer = false # Allow part to be not an integer
31
+ part
32
+ end
33
+
34
+ if only_integer && non_negative && part < 0
35
+ raise WrongVersionError, "#{name} version cannot be negative"
36
+ end
37
+
38
+ if !is_integer && part !~ PART_REGEXP
39
+ raise WrongVersionError, "#{name} can contain only ASCII alphanumerics and hyphen"
40
+ end
41
+
42
+ part
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,63 @@
1
+ module Fv
2
+ class Error < StandardError;
3
+ end
4
+ class WrongVersionError < Error;
5
+ end
6
+
7
+ class V
8
+ ##
9
+ # Behaviour
10
+ #
11
+ include Comparable
12
+
13
+ ##
14
+ # Attributes
15
+ #
16
+ attr_reader :parts, :major, :minor, :patch
17
+
18
+ ##
19
+ # Instance methods
20
+ #
21
+ def initialize(major, minor, patch)
22
+ @major = major
23
+ @minor = minor
24
+ @patch = patch
25
+
26
+ @parts = [@major, @minor, @patch]
27
+ end
28
+
29
+ def to_s
30
+ parts.join('.')
31
+ end
32
+
33
+ def prerelease?
34
+ !patch.is_a?(Integer)
35
+ end
36
+
37
+ def <=>(other)
38
+ other = Fv.parse(other) unless other.is_a?(V)
39
+
40
+ major_cmp = @major <=> other.major
41
+ return major_cmp unless major_cmp.zero?
42
+
43
+ minor_cmp = @minor <=> other.minor
44
+ return minor_cmp unless minor_cmp.zero?
45
+
46
+ patch_cmp = @patch <=> other.patch
47
+ return patch_cmp if patch_cmp && !patch_cmp.zero?
48
+
49
+ this_pre = prerelease? ? 0 : 1
50
+ other_pre = other.prerelease? ? 0 : 1
51
+ both_prerelease = prerelease? && other.prerelease?
52
+ return this_pre <=> other_pre unless both_prerelease
53
+
54
+ prerelease_compare(other)
55
+ end
56
+
57
+ private
58
+ def prerelease_compare(other)
59
+ # TODO
60
+ end
61
+ end
62
+ end
63
+
@@ -0,0 +1,3 @@
1
+ module Fv
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alex Tonkonozhenko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description:
56
+ email:
57
+ - tonkonozhenko@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - fv.gemspec
70
+ - lib/fv.rb
71
+ - lib/fv/all.rb
72
+ - lib/fv/core_ext.rb
73
+ - lib/fv/core_ext/object.rb
74
+ - lib/fv/parser.rb
75
+ - lib/fv/v.rb
76
+ - lib/fv/version.rb
77
+ homepage: https://github.com/tonkonozhenko/fv
78
+ licenses:
79
+ - MIT
80
+ metadata:
81
+ allowed_push_host: https://rubygems.org
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.5.1
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Fv is gem for fast operations with version numbers
102
+ test_files: []