to_range 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.travis.yml +0 -1
- data/README.md +18 -9
- data/Rakefile +6 -1
- data/features/step_definitions/to_range_steps.rb +33 -0
- data/features/to_range.feature +21 -0
- data/lib/to_range/string.rb +5 -4
- data/lib/to_range/version.rb +1 -1
- data/spec/lib/string_spec.rb +8 -7
- data/to_range.gemspec +1 -0
- data/to_range.png +0 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b65f779ac8b6f64f0a6d9318112e182980043aac
|
4
|
+
data.tar.gz: 7da5cdc9aa59d7ea387e7429c5974bb4467b397e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4df14998f05d8e7888b576257ee297a8aa7efcc4fb60f0b2e33fcf86b9bc1982089cc028ed920e0b32e9f970a81a637366a0f105bd87c0f2f8ab82d649450ea5
|
7
|
+
data.tar.gz: cb4ca44c134fc3a31e827d66d2864b9272c3c0a3178f5291f4440e98d4499794b5f635f59a73cd1450191f4c91d7edad7f01fd14ee6163777a7df6c275d45f99
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,21 @@
|
|
1
|
-
#
|
1
|
+
# to_range [](https://codeclimate.com/github/metaware/to_range) [](https://travis-ci.org/metaware/to_range)
|
2
2
|
|
3
|
-
|
3
|
+

|
4
|
+
|
5
|
+
Ruby Gem to Convert strings (parsable) into Range Objects
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
irb(main):001:0> "1..10".to_range
|
10
|
+
=> 1..10
|
11
|
+
=> PROFIT!
|
12
|
+
|
13
|
+
For any ambiguous cases, where there might be multiple matches of a possible range, This library assumes you need only the first possible, valid-looking Range match, ex:
|
14
|
+
|
15
|
+
irb(main):001:0> "1.10..50..100".to_range
|
16
|
+
=> 10..50
|
17
|
+
|
18
|
+
**PS: It blows on your face, if it's unable to find a possible parsable match.**
|
4
19
|
|
5
20
|
## Installation
|
6
21
|
|
@@ -16,16 +31,10 @@ Or install it yourself as:
|
|
16
31
|
|
17
32
|
$ gem install to_range
|
18
33
|
|
19
|
-
## Usage
|
20
|
-
|
21
|
-
irb(main):001:0> "1..10".to_range
|
22
|
-
=> 1..10
|
23
|
-
=> PROFIT!
|
24
|
-
|
25
34
|
## Contributing
|
26
35
|
|
27
36
|
1. Fork it
|
28
37
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
38
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
39
|
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
-
5. Create new Pull Request
|
40
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
require 'rake/testtask'
|
2
2
|
require 'bundler/gem_tasks'
|
3
3
|
require 'rspec/core/rake_task'
|
4
|
+
require 'cucumber/rake/task'
|
4
5
|
|
5
|
-
|
6
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
7
|
+
t.cucumber_opts = "features --format pretty"
|
8
|
+
end
|
9
|
+
|
10
|
+
task :default => [:features, :spec]
|
6
11
|
|
7
12
|
RSpec::Core::RakeTask.new
|
8
13
|
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'to_range'
|
2
|
+
|
3
|
+
Transform /^(-?\d+)$/ do |number|
|
4
|
+
number.to_i
|
5
|
+
end
|
6
|
+
|
7
|
+
Given(/^we have a string that looks like "(.*?)"$/) do |test_str|
|
8
|
+
@test_str = test_str
|
9
|
+
end
|
10
|
+
|
11
|
+
When(/^we try to convert this string into a range object by calling to_range on the string$/) do
|
12
|
+
@result = @test_str.to_range
|
13
|
+
end
|
14
|
+
|
15
|
+
When(/^we try to convert this non\-parseable string into a range object by calling to_range on the string$/) do
|
16
|
+
expect { @test_str.to_range }.to raise_error
|
17
|
+
end
|
18
|
+
|
19
|
+
Then(/^we should get a range object$/) do
|
20
|
+
expect(@result).to be_an_instance_of(Range)
|
21
|
+
end
|
22
|
+
|
23
|
+
Then(/^it should raise an exception$/) do
|
24
|
+
pending # express the regexp above with the code you wish you had
|
25
|
+
end
|
26
|
+
|
27
|
+
Then(/^we should not get a range object$/) do
|
28
|
+
expect(@result).to_not be_an_instance_of(Range)
|
29
|
+
end
|
30
|
+
|
31
|
+
Then(/^it should range from "(.*?)" to "(.*?)"$/) do |from, to|
|
32
|
+
expect(@result).to eq(from..to)
|
33
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
Feature: to_range
|
2
|
+
In order to convert range looking strings into ruby range objects
|
3
|
+
As a Ruby developer
|
4
|
+
I should be able to use to_range gem
|
5
|
+
|
6
|
+
Scenario: string is parseable to a range object
|
7
|
+
Given we have a string that looks like "0..10"
|
8
|
+
When we try to convert this string into a range object by calling to_range on the string
|
9
|
+
Then we should get a range object
|
10
|
+
And it should range from "0" to "10"
|
11
|
+
|
12
|
+
Scenario: string is not parseable to a range object
|
13
|
+
Given we have a string that looks like "010"
|
14
|
+
When we try to convert this non-parseable string into a range object by calling to_range on the string
|
15
|
+
Then we should not get a range object
|
16
|
+
|
17
|
+
Scenario: string is ambiguous
|
18
|
+
Given we have a string that looks like "100..105..115"
|
19
|
+
When we try to convert this string into a range object by calling to_range on the string
|
20
|
+
Then we should get a range object
|
21
|
+
And it should range from "100" to "105"
|
data/lib/to_range/string.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
class
|
1
|
+
class StringToRangeConversionFailed < StandardError; end
|
2
2
|
|
3
3
|
class String
|
4
4
|
|
5
5
|
def to_range
|
6
6
|
str = scan(/\d+\.{2,3}\d+/).first
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
if str
|
8
|
+
dots = str.count('.')
|
9
|
+
else
|
10
|
+
raise StringToRangeConversionFailed
|
10
11
|
end
|
11
12
|
three_dots = (dots == 3)
|
12
13
|
arr = three_dots ? str.split('...') : str.split('..')
|
data/lib/to_range/version.rb
CHANGED
data/spec/lib/string_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe String do
|
|
24
24
|
|
25
25
|
context 'ambiguous cases' do
|
26
26
|
|
27
|
-
it 'parses the first
|
27
|
+
it 'parses the first parsable occurrence' do
|
28
28
|
expect('1..5..10'.to_range).to eq(1..5)
|
29
29
|
expect('1.5..10'.to_range).to eq(5..10)
|
30
30
|
expect('15..10...20'.to_range).to eq(15..10)
|
@@ -39,12 +39,13 @@ describe String do
|
|
39
39
|
|
40
40
|
context "exception cases" do
|
41
41
|
|
42
|
-
it 'raises an exception when the string is not
|
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
|
42
|
+
it 'raises an exception when the string is not parsable' do
|
43
|
+
expect { '1.4.6'.to_range }.to raise_exception(StringToRangeConversionFailed)
|
44
|
+
expect { '146'.to_range }.to raise_exception(StringToRangeConversionFailed)
|
45
|
+
expect { '1.4..'.to_range }.to raise_exception(StringToRangeConversionFailed)
|
46
|
+
expect { '..1.4..'.to_range }.to raise_exception(StringToRangeConversionFailed)
|
47
|
+
expect { '..14..'.to_range }.to raise_exception(StringToRangeConversionFailed)
|
48
|
+
expect { '1234'.to_range }.to raise_exception(StringToRangeConversionFailed)
|
48
49
|
end
|
49
50
|
|
50
51
|
end
|
data/to_range.gemspec
CHANGED
data/to_range.png
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: to_range
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jasdeep Singh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cucumber
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Gem to parse Range like strings to actual Range Objects
|
56
70
|
email:
|
57
71
|
- jasdeep@metawarelabs.com
|
@@ -66,6 +80,8 @@ files:
|
|
66
80
|
- LICENSE.txt
|
67
81
|
- README.md
|
68
82
|
- Rakefile
|
83
|
+
- features/step_definitions/to_range_steps.rb
|
84
|
+
- features/to_range.feature
|
69
85
|
- lib/to_range.rb
|
70
86
|
- lib/to_range/string.rb
|
71
87
|
- lib/to_range/version.rb
|
@@ -73,6 +89,7 @@ files:
|
|
73
89
|
- spec/spec_helper.rb
|
74
90
|
- spec/to_range_spec.rb
|
75
91
|
- to_range.gemspec
|
92
|
+
- to_range.png
|
76
93
|
homepage: http://github.com/metaware/to_range
|
77
94
|
licenses:
|
78
95
|
- MIT
|
@@ -98,6 +115,8 @@ signing_key:
|
|
98
115
|
specification_version: 4
|
99
116
|
summary: Ruby String extensiion to parse Range like strings to actual Range Objects
|
100
117
|
test_files:
|
118
|
+
- features/step_definitions/to_range_steps.rb
|
119
|
+
- features/to_range.feature
|
101
120
|
- spec/lib/string_spec.rb
|
102
121
|
- spec/spec_helper.rb
|
103
122
|
- spec/to_range_spec.rb
|