to_range 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0217ba92e178aae603550a851aded71ccc82b1b7
4
+ data.tar.gz: e6a5b0439ecb02e6af9acfbe593ba4027ff078bd
5
+ SHA512:
6
+ metadata.gz: ef771bb89354879ba882fe6ba68ab7c7bec1bf44ceab69eaf4ad455015dd4013970893695f1554a6e67956d979b30f3a5198327fbaca72fceaba27a38ef0571d
7
+ data.tar.gz: 24f820934435443bace8a9bbaeddbc975ef76fd76e77b6e866edf59686c338a3e710b6e3113e22aebdd2fe0fe2da95a730dca6cf9f296681536c358aab1348f4
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
4
+ - 2.0.0
5
+ - 1.9.3
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-2.1.1
9
+ - 1.8.7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in to_range.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jasdeep Singh
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # ToRange [![Code Climate](https://codeclimate.com/github/metaware/to_range/badges/gpa.svg)](https://codeclimate.com/github/metaware/to_range) [![Build Status](https://travis-ci.org/metaware/to_range.svg?branch=master)](https://travis-ci.org/metaware/to_range)
2
+
3
+ Small Ruby Gem to Convert strings (parseable) into Range Objects
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'to_range'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install to_range
18
+
19
+ ## Usage
20
+
21
+ irb(main):001:0> "1..10".to_range
22
+ => 1..10
23
+ => PROFIT!
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'rake/testtask'
2
+ require 'bundler/gem_tasks'
3
+ require 'rspec/core/rake_task'
4
+
5
+ task :default => :spec
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ #Bundler::GemHelper.install_tasks
10
+
11
+ #task default: :test
@@ -0,0 +1,18 @@
1
+ class ToRangeParseFailed < StandardError; end
2
+
3
+ class String
4
+
5
+ def to_range
6
+ str = scan(/\d+\.{2,3}\d+/).first
7
+ dots = str.count('.')
8
+ if dots > 3
9
+ raise ToRangeParseFailed
10
+ end
11
+ three_dots = (dots == 3)
12
+ arr = three_dots ? str.split('...') : str.split('..')
13
+ first = arr.first.to_i
14
+ last = arr.last.to_i
15
+ three_dots ? first...last : first..last
16
+ end
17
+
18
+ end
@@ -0,0 +1,3 @@
1
+ module ToRange
2
+ VERSION = "0.0.1"
3
+ end
data/lib/to_range.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "to_range/version"
2
+ require "to_range/string"
3
+
4
+ module ToRange
5
+
6
+ end
@@ -0,0 +1,54 @@
1
+ require 'to_range'
2
+
3
+ describe String do
4
+
5
+ describe "#to_range" do
6
+
7
+ let(:range) { "1..10".to_range }
8
+
9
+ it 'strings respond to #to_range method' do
10
+ expect("string").to respond_to(:to_range)
11
+ end
12
+
13
+ it 'can parse a string to a range object' do
14
+ expect(range).to eq(1..10)
15
+ end
16
+
17
+ it 'returns an object of Range class' do
18
+ expect(range.class).to eq(Range)
19
+ end
20
+
21
+ it 'can parse ... (3 dots) as well' do
22
+ expect("1...10".to_range).to eq(1...10)
23
+ end
24
+
25
+ context 'ambiguous cases' do
26
+
27
+ it 'parses the first parseable occurrence' do
28
+ expect('1..5..10'.to_range).to eq(1..5)
29
+ expect('1.5..10'.to_range).to eq(5..10)
30
+ expect('15..10...20'.to_range).to eq(15..10)
31
+ expect('1...10.15'.to_range).to eq(1...10)
32
+ expect('1.17.10..20'.to_range).to eq(10..20)
33
+ expect('1.17.10...20'.to_range).to eq(10...20)
34
+ expect('..2..5..8..10..'.to_range).to eq(2..5)
35
+ expect('...2.5.8...10..'.to_range).to eq(8...10)
36
+ end
37
+
38
+ end
39
+
40
+ context "exception cases" do
41
+
42
+ it 'raises an exception when the string is not parseable' do
43
+ expect { '1.4.6'.to_range }.to raise_exception
44
+ expect { '146'.to_range }.to raise_exception
45
+ expect { '1.4..'.to_range }.to raise_exception
46
+ expect { '..1.4..'.to_range }.to raise_exception
47
+ expect { '..14..'.to_range }.to raise_exception
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require 'to_range'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
@@ -0,0 +1,4 @@
1
+
2
+ describe ToRange do
3
+
4
+ end
data/to_range.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'to_range/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "to_range"
8
+ spec.version = ToRange::VERSION
9
+ spec.authors = ["Jasdeep Singh"]
10
+ spec.email = ["jasdeep@metawarelabs.com"]
11
+ spec.description = %q{Gem to parse Range like strings to actual Range Objects}
12
+ spec.summary = %q{Ruby String extensiion to parse Range like strings to actual Range Objects}
13
+ spec.homepage = "http://github.com/metaware/to_range"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to_range
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jasdeep Singh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-18 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Gem to parse Range like strings to actual Range Objects
56
+ email:
57
+ - jasdeep@metawarelabs.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
+ - lib/to_range.rb
70
+ - lib/to_range/string.rb
71
+ - lib/to_range/version.rb
72
+ - spec/lib/string_spec.rb
73
+ - spec/spec_helper.rb
74
+ - spec/to_range_spec.rb
75
+ - to_range.gemspec
76
+ homepage: http://github.com/metaware/to_range
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.4.5
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Ruby String extensiion to parse Range like strings to actual Range Objects
100
+ test_files:
101
+ - spec/lib/string_spec.rb
102
+ - spec/spec_helper.rb
103
+ - spec/to_range_spec.rb