cornell_netid 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +15 -0
- data/README.rdoc +20 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/cornell_netid.gemspec +56 -0
- data/lib/core_extensions/string.rb +39 -0
- data/lib/cornell_netid.rb +8 -0
- data/spec/cornell_netid_spec.rb +42 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +9 -0
- metadata +77 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
Copyright (c) 2009 Ari Epstein
|
2
|
+
|
3
|
+
This program is free software: you can redistribute it and/or modify
|
4
|
+
it under the terms of the GNU General Public License as published by
|
5
|
+
the Free Software Foundation, either version 3 of the License, or
|
6
|
+
(at your option) any later version.
|
7
|
+
|
8
|
+
This program is distributed in the hope that it will be useful,
|
9
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
GNU General Public License for more details.
|
12
|
+
|
13
|
+
You should have received a copy of the GNU General Public License
|
14
|
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
= cornell_netid
|
2
|
+
|
3
|
+
Toolkit for handling Cornell University Net Ids. Extends the String class
|
4
|
+
with several methods that make it easier to parse net ids.
|
5
|
+
|
6
|
+
== Note on Patches/Pull Requests
|
7
|
+
|
8
|
+
* Fork the project.
|
9
|
+
* Make your feature addition or bug fix.
|
10
|
+
* Add tests for it. This is important so I don't break it in a
|
11
|
+
future version unintentionally.
|
12
|
+
* Commit, do not mess with rakefile, version, or history.
|
13
|
+
(if you want to have your own version, that is fine but
|
14
|
+
bump version in a commit by itself I can ignore when I pull)
|
15
|
+
* Send me a pull request. Bonus points for topic branches.
|
16
|
+
|
17
|
+
== Copyright
|
18
|
+
|
19
|
+
Copyright (c) 2009 Ari Epstein. See LICENSE for details.
|
20
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "cornell_netid"
|
8
|
+
gem.summary = %Q{Cornell Net Id Extensions}
|
9
|
+
gem.description = %Q{Toolkit for handling Cornell University Net Ids. Extends the String class with several methods that make it easier to parse net ids.}
|
10
|
+
gem.email = "aepstein607@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/aepstein/cornell_netid"
|
12
|
+
gem.authors = ["Ari Epstein"]
|
13
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
14
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
15
|
+
end
|
16
|
+
Jeweler::GemcutterTasks.new
|
17
|
+
rescue LoadError
|
18
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'spec/rake/spectask'
|
22
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
23
|
+
spec.libs << 'lib' << 'spec'
|
24
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
25
|
+
end
|
26
|
+
|
27
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
28
|
+
spec.libs << 'lib' << 'spec'
|
29
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
30
|
+
spec.rcov = true
|
31
|
+
end
|
32
|
+
|
33
|
+
task :spec => :check_dependencies
|
34
|
+
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'rake/rdoctask'
|
38
|
+
Rake::RDocTask.new do |rdoc|
|
39
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "cornell_netid #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
46
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{cornell_netid}
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ari Epstein"]
|
12
|
+
s.date = %q{2009-11-05}
|
13
|
+
s.description = %q{Toolkit for handling Cornell University Net Ids. Extends the String class with several methods that make it easier to parse net ids.}
|
14
|
+
s.email = %q{aepstein607@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"cornell_netid.gemspec",
|
27
|
+
"lib/core_extensions/string.rb",
|
28
|
+
"lib/cornell_netid.rb",
|
29
|
+
"spec/cornell_netid_spec.rb",
|
30
|
+
"spec/spec.opts",
|
31
|
+
"spec/spec_helper.rb"
|
32
|
+
]
|
33
|
+
s.homepage = %q{http://github.com/aepstein/cornell_netid}
|
34
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
35
|
+
s.require_paths = ["lib"]
|
36
|
+
s.rubygems_version = %q{1.3.5}
|
37
|
+
s.summary = %q{Cornell Net Id Extensions}
|
38
|
+
s.test_files = [
|
39
|
+
"spec/cornell_netid_spec.rb",
|
40
|
+
"spec/spec_helper.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
49
|
+
else
|
50
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
51
|
+
end
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CornellNetid::CoreExtensions
|
2
|
+
module String
|
3
|
+
|
4
|
+
# Returns an array of strings representing valid netids contained in the
|
5
|
+
# source string. The source string may contain multiple netids or
|
6
|
+
# netid@cornell.edu addresses separated by any of these characters:
|
7
|
+
#
|
8
|
+
# * , ; \ / : whitespace
|
9
|
+
def to_net_ids
|
10
|
+
ids = self.split(/[\,\;\\\/\s\:]+/)
|
11
|
+
ids.map! { |part| part.to_net_id }
|
12
|
+
ids.reject! { |part| part.nil? }
|
13
|
+
ids.uniq
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns a string representing a valid net id parsed out of the string
|
17
|
+
def to_net_id
|
18
|
+
self.strip.downcase[CornellNetid::PARSEABLE_NET_ID,1]
|
19
|
+
end
|
20
|
+
|
21
|
+
# Converts the string to a valid netid if it contains one
|
22
|
+
# Throws InvalidNetidError if no valid net id is contained in string
|
23
|
+
def to_net_id!
|
24
|
+
id = self.to_net_id
|
25
|
+
raise CornellNetid::InvalidNetidError if id.nil?
|
26
|
+
self[self] = id unless self == id
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns true if the string is a valid net id
|
30
|
+
def valid_net_id?
|
31
|
+
self.match(CornellNetid::VALID_NET_ID) ? true : false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class String
|
37
|
+
include CornellNetid::CoreExtensions::String
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "CornellNetid" do
|
4
|
+
before(:all) do
|
5
|
+
@valid_email = 'ate2@cornell.edu'
|
6
|
+
@invalid_email = '2ate@cornll.edu'
|
7
|
+
@valid = 'zzz1'
|
8
|
+
@invalid = '1zzz'
|
9
|
+
end
|
10
|
+
|
11
|
+
it "adds valid_net_id? instance method to String" do
|
12
|
+
@valid.valid_net_id?.should eql(true)
|
13
|
+
@invalid.valid_net_id?.should eql(false)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "adds to_net_id instance method to String" do
|
17
|
+
@valid.to_net_id.should eql 'zzz1'
|
18
|
+
@valid_email.to_net_id.should eql 'ate2'
|
19
|
+
@valid_email.upcase.to_net_id.should eql 'ate2'
|
20
|
+
@invalid.to_net_id.should be_nil
|
21
|
+
@invalid_email.to_net_id.should be_nil
|
22
|
+
end
|
23
|
+
|
24
|
+
it "adds to_net_ids instance method to String" do
|
25
|
+
[ ' ', ';', '/', ',', '\\', ':' ].each do |s|
|
26
|
+
result = "#{@valid}#{s}#{@invalid}#{s}#{@valid_email}#{s}#{@invalid_email}".to_net_ids
|
27
|
+
result.size.should eql 2
|
28
|
+
result.should include 'zzz1'
|
29
|
+
result.should include 'ate2'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "adds to_net_id! instance method to String" do
|
34
|
+
lambda { @valid_email.to_net_id! }.should_not raise_error
|
35
|
+
@valid_email.should eql 'ate2'
|
36
|
+
lambda { @valid.to_net_id! }.should_not raise_error
|
37
|
+
@valid.should eql 'zzz1'
|
38
|
+
lambda { @invalid_email.to_net_id! }.should raise_error CornellNetid::InvalidNetidError
|
39
|
+
lambda { @invalid.to_net_id! }.should raise_error CornellNetid::InvalidNetidError
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cornell_netid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ari Epstein
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-05 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
type: :development
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.2.9
|
24
|
+
version:
|
25
|
+
description: Toolkit for handling Cornell University Net Ids. Extends the String class with several methods that make it easier to parse net ids.
|
26
|
+
email: aepstein607@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- LICENSE
|
33
|
+
- README.rdoc
|
34
|
+
files:
|
35
|
+
- .document
|
36
|
+
- .gitignore
|
37
|
+
- LICENSE
|
38
|
+
- README.rdoc
|
39
|
+
- Rakefile
|
40
|
+
- VERSION
|
41
|
+
- cornell_netid.gemspec
|
42
|
+
- lib/core_extensions/string.rb
|
43
|
+
- lib/cornell_netid.rb
|
44
|
+
- spec/cornell_netid_spec.rb
|
45
|
+
- spec/spec.opts
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/aepstein/cornell_netid
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Cornell Net Id Extensions
|
75
|
+
test_files:
|
76
|
+
- spec/cornell_netid_spec.rb
|
77
|
+
- spec/spec_helper.rb
|