Skip to content

Commit

Permalink
Initial version completed.
Browse files Browse the repository at this point in the history
  • Loading branch information
aepstein committed Nov 5, 2009
1 parent e6e4ea1 commit aa5255c
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 24 deletions.
27 changes: 11 additions & 16 deletions LICENSE
@@ -1,20 +1,15 @@
Copyright (c) 2009 Ari Epstein

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
5 changes: 3 additions & 2 deletions Rakefile
Expand Up @@ -5,8 +5,8 @@ begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "cornell_netid"
gem.summary = %Q{TODO: one-line summary of your gem}
gem.description = %Q{TODO: longer description of your gem}
gem.summary = %Q{Cornell Net Id Extensions}
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.}
gem.email = "aepstein607@gmail.com"
gem.homepage = "http://github.com/aepstein/cornell_netid"
gem.authors = ["Ari Epstein"]
Expand Down Expand Up @@ -43,3 +43,4 @@ Rake::RDocTask.new do |rdoc|
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end

55 changes: 55 additions & 0 deletions cornell_netid.gemspec
@@ -0,0 +1,55 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{cornell_netid}
s.version = "0.0.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Ari Epstein"]
s.date = %q{2009-11-05}
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.}
s.email = %q{aepstein607@gmail.com}
s.extra_rdoc_files = [
"LICENSE",
"README.rdoc"
]
s.files = [
".document",
".gitignore",
"LICENSE",
"README.rdoc",
"Rakefile",
"VERSION",
"lib/core_extensions/string.rb",
"lib/cornell_netid.rb",
"spec/cornell_netid_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb"
]
s.homepage = %q{http://github.com/aepstein/cornell_netid}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.5}
s.summary = %q{Cornell Net Id Extensions}
s.test_files = [
"spec/cornell_netid_spec.rb",
"spec/spec_helper.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
else
s.add_dependency(%q<rspec>, [">= 1.2.9"])
end
else
s.add_dependency(%q<rspec>, [">= 1.2.9"])
end
end

15 changes: 12 additions & 3 deletions lib/core_extensions/string.rb
@@ -1,23 +1,32 @@
module CornellNetid::CoreExtensions
module String
# Return an array of net_id strings from an input string

# Returns an array of strings representing valid netids contained in the
# source string. The source string may contain multiple netids or
# netid@cornell.edu addresses separated by any of these characters:
#
# * , ; \ / : whitespace
def to_net_ids
ids = self.split(/[\,\;\\\/\s]+/)
ids = self.split(/[\,\;\\\/\s\:]+/)
ids.map! { |part| part.to_net_id }
ids.reject! { |part| part.nil? }
ids.uniq
end

# Returns a string representing a valid net id parsed out of the string
def to_net_id
self.strip.downcase[CornellNetid::VALID_NET_ID_WITH_EMAIL,1]
self.strip.downcase[CornellNetid::PARSEABLE_NET_ID,1]
end

# Converts the string to a valid netid if it contains one
# Throws InvalidNetidError if no valid net id is contained in string
def to_net_id!
id = self.to_net_id
raise CornellNetid::InvalidNetidError if id.nil?
self[self] = id unless self == id
end

# Returns true if the string is a valid net id
def valid_net_id?
self.match(CornellNetid::VALID_NET_ID) ? true : false
end
Expand Down
4 changes: 2 additions & 2 deletions lib/cornell_netid.rb
@@ -1,6 +1,6 @@
module CornellNetid
VALID_NET_ID = /^\w{2,3}\d+$/i
VALID_NET_ID_WITH_EMAIL = /^(\w{2,3}\d+)(@cornell\.edu)?$/i
VALID_NET_ID = /^[a-z]{2,3}\d+$/
PARSEABLE_NET_ID = /^([A-Za-z]{2,3}\d+)(@cornell\.edu)?$/i
class InvalidNetidError < RuntimeError; end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/cornell_netid_spec.rb
Expand Up @@ -16,12 +16,13 @@
it "adds to_net_id instance method to String" do
@valid.to_net_id.should eql 'zzz1'
@valid_email.to_net_id.should eql 'ate2'
@valid_email.upcase.to_net_id.should eql 'ate2'
@invalid.to_net_id.should be_nil
@invalid_email.to_net_id.should be_nil
end

it "adds to_net_ids instance method to String" do
[ ' ', ';', '/', ',' ].each do |s|
[ ' ', ';', '/', ',', '\\', ':' ].each do |s|
result = "#{@valid}#{s}#{@invalid}#{s}#{@valid_email}#{s}#{@invalid_email}".to_net_ids
result.size.should eql 2
result.should include 'zzz1'
Expand Down

0 comments on commit aa5255c

Please sign in to comment.