sixarm_ruby_range_parse 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # SixArm.com » Ruby » <br> Range.parse method to convert text to a Range object.
2
+
3
+ * Doc: <http://sixarm.com/sixarm_ruby_range_parse/doc>
4
+ * Gem: <http://rubygems.org/gems/sixarm_ruby_range_parse>
5
+ * Repo: <http://github.com/sixarm/sixarm_ruby_range_parse>
6
+ * Email: Joel Parker Henderson, <joel@sixarm.com>
7
+
8
+ ## Introduction
9
+
10
+ Parse a text string to a range.
11
+
12
+ To include the end item, use two dots:
13
+
14
+ Range.parse("a..z") #=> "a".."z"
15
+
16
+ To exclude the end item, use three dots:
17
+
18
+ Range.parse("a...z") #=> "a"..."z"
19
+
20
+ The parse method calls #to_s on its input:
21
+
22
+ class Foo
23
+ def to_s
24
+ "hello..world"
25
+ end
26
+ end
27
+
28
+ Range.parse(Foo.new) #=> "hello".."world"
29
+
30
+ The parse method uses the same dot notation as Range#to_s which enables round trips:
31
+
32
+ range = Range.parse("hello..world")
33
+ range.to_s #=> "hello..world"
34
+
35
+
36
+ For docs go to <http://sixarm.com/sixarm_ruby_range_parse/doc>
37
+
38
+ Want to help? We're happy to get pull requests.
39
+
40
+
41
+ ## Install quickstart
42
+
43
+ Install:
44
+
45
+ gem install sixarm_ruby_range_parse
46
+
47
+ Bundler:
48
+
49
+ gem "sixarm_ruby_range_parse", "~>1.0.0"
50
+
51
+ Require:
52
+
53
+ require "sixarm_ruby_range_parse"
54
+
55
+
56
+ ## Install with security (optional)
57
+
58
+ To enable high security for all our gems:
59
+
60
+ wget http://sixarm.com/sixarm.pem
61
+ gem cert --add sixarm.pem
62
+ gem sources --add http://sixarm.com
63
+
64
+ To install with high security:
65
+
66
+ gem install sixarm_ruby_range_parse --test --trust-policy HighSecurity
67
+
68
+
69
+ ## Changes
70
+
71
+ * 2012-09-19 1.0.1 Add string conversion and round-trip test
72
+ * 2012-09-18 1.0.0 Publish extracted code from existing app
73
+
74
+
75
+ ## License
76
+
77
+ You may choose any of these open source licenses:
78
+
79
+ * Apache License
80
+ * BSD License
81
+ * CreativeCommons License, Non-commercial Share Alike
82
+ * GNU General Public License Version 2 (GPL 2)
83
+ * GNU Lesser General Public License (LGPL)
84
+ * MIT License
85
+ * Perl Artistic License
86
+ * Ruby License
87
+
88
+ The software is provided "as is", without warranty of any kind,
89
+ express or implied, including but not limited to the warranties of
90
+ merchantability, fitness for a particular purpose and noninfringement.
91
+
92
+ In no event shall the authors or copyright holders be liable for any
93
+ claim, damages or other liability, whether in an action of contract,
94
+ tort or otherwise, arising from, out of or in connection with the
95
+ software or the use or other dealings in the software.
96
+
97
+ This license is for the included software that is created by SixArm;
98
+ some of the included software may have its own licenses, copyrights,
99
+ authors, etc. and these do take precedence over the SixArm license.
100
+
101
+ Copyright (c) 2005-2012 Joel Parker Henderson
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rake'
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:test) do |t|
6
+ t.libs << 'lib' << 'test'
7
+ t.pattern = 'test/*.rb'
8
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.1
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin rdoc
3
+ Please see README
4
+ =end
5
+
6
+ class Range
7
+
8
+ # Parse the text to a pair of tokens and return these as a new range object.
9
+ #
10
+ # The separator may be two dots or three dots:
11
+ #
12
+ # * Two dots ".." includes the stop item.
13
+ # * Three dots "..." excludes the stop item.
14
+ #
15
+ # This method delegates parsing of each tokens to Range.parse_helper
16
+ #
17
+ def self.parse(text)
18
+ begin
19
+ text=text.to_s
20
+ if text=~/(\.\.\.?)/
21
+ start_token = $`
22
+ stop_token = $'
23
+ separator = $1
24
+ exclude_end = (separator == "...")
25
+ return self.new(self.parse_helper(start_token), self.parse_helper(stop_token), exclude_end)
26
+ end
27
+ rescue
28
+ end
29
+ raise ArgumentError.new("#parse text must have a start token, two or three dots, and a stop token; this text does not parse: \"#{text}\"")
30
+ end
31
+
32
+ # Parse one item of the pair of items.
33
+ # Subclasses will likely want to override this.
34
+ #
35
+ def self.parse_helper(text)
36
+ text
37
+ end
38
+
39
+ end
40
+
@@ -0,0 +1,40 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'minitest/autorun'
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'sixarm_ruby_range_parse'
6
+
7
+ describe Range do
8
+
9
+ describe "#parse" do
10
+
11
+ it "parses two dots as a range including the end" do
12
+ Range.parse("a..z").must_equal "a".."z"
13
+ end
14
+
15
+ it "parses three dots as a range including the end" do
16
+ Range.parse("a...z").must_equal "a"..."z"
17
+ end
18
+
19
+ it "calls to_s on the input" do
20
+ x = Object.new
21
+ def x.to_s; "a..z"; end
22
+ Range.parse(x).must_equal "a".."z"
23
+ end
24
+
25
+ it "round trips" do
26
+ range = "a".."z"
27
+ Range.parse(range).must_equal range
28
+ end
29
+
30
+ end
31
+
32
+ describe "#parse_helper" do
33
+
34
+ it "is pass through (subclasses will override this method)" do
35
+ Range.parse_helper("a").must_equal ("a")
36
+ end
37
+
38
+ end
39
+
40
+ end
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sixarm_ruby_range_parse
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - SixArm
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain:
12
+ - !binary |-
13
+ LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURCRENDQW0yZ0F3SUJB
14
+ Z0lKQUtQd0VFVFU1YkhvTUEwR0NTcUdTSWIzRFFFQkJRVUFNR0F4Q3pBSkJn
15
+ TlYKQkFZVEFsVlRNUk13RVFZRFZRUUlFd3BEWVd4cFptOXlibWxoTVJZ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+ VTViSG9NQXdHQTFVZEV3UUYKTUFNQkFmOHdEUVlKS29aSWh2Y05BUUVGQlFB
33
+ RGdZRUFvb0VleFAvb1BhbTFUUDcxU3l1aHhNYit1VHJaYlNRZQpqVkIrRXhS
34
+ d1dhZEd3YU5QVUE1NmQzOXF3YXZ3UCtpdSszSnBlb25OTVZ2YldYRjVuYUNY
35
+ L2RORkllUkVIekVSClpEUlFZTXFydTlURU1uYTZIRDl6cGNzdEY3dndUaEdv
36
+ dmxPUSszWTZwbFE0bk16aXBYY1o5VEhxczY1UElMMHEKZWFid3BDYkFvcG89
37
+ Ci0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0K
38
+ date: 2012-09-20 00:00:00.000000000 Z
39
+ dependencies: []
40
+ description:
41
+ email: sixarm@sixarm.com
42
+ executables: []
43
+ extensions: []
44
+ extra_rdoc_files: []
45
+ files:
46
+ - .gemtest
47
+ - Rakefile
48
+ - README.md
49
+ - VERSION
50
+ - lib/sixarm_ruby_range_parse.rb
51
+ - test/sixarm_ruby_range_parse_test.rb
52
+ homepage: http://sixarm.com/
53
+ licenses: []
54
+ post_install_message:
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 1.8.23
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: SixArm.com » Ruby » Range.parse method to convert text to a Range object
76
+ test_files:
77
+ - test/sixarm_ruby_range_parse_test.rb
78
+ has_rdoc: true
metadata.gz.sig ADDED
Binary file