email_list 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use ree" > .rvmrc
9
+ environment_id="ree-1.8.7-2011.12@email_list"
10
+
11
+ #
12
+ # Uncomment the following lines if you want to verify rvm version per project
13
+ #
14
+ # rvmrc_rvm_version="1.10.2" # 1.10.1 seams as a safe start
15
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
16
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
17
+ # return 1
18
+ # }
19
+ #
20
+
21
+ #
22
+ # Uncomment following line if you want options to be set only for given project.
23
+ #
24
+ # PROJECT_JRUBY_OPTS=( --1.9 )
25
+ #
26
+ # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
27
+ #
28
+ # chmod +x ${rvm_path}/hooks/after_use_jruby_opts
29
+ #
30
+
31
+ #
32
+ # First we attempt to load the desired environment directly from the environment
33
+ # file. This is very fast and efficient compared to running through the entire
34
+ # CLI and selector. If you want feedback on which environment was used then
35
+ # insert the word 'use' after --create as this triggers verbose mode.
36
+ #
37
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
38
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
39
+ then
40
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
41
+
42
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
43
+ then
44
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
45
+ fi
46
+ else
47
+ # If the environment file has not yet been created, use the RVM CLI to select.
48
+ if ! rvm --create "$environment_id"
49
+ then
50
+ echo "Failed to create RVM environment '${environment_id}'."
51
+ return 1
52
+ fi
53
+ fi
54
+
55
+ #
56
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
57
+ # it be automatically loaded. Uncomment the following and adjust the filename if
58
+ # necessary.
59
+ #
60
+ # filename=".gems"
61
+ # if [[ -s "$filename" ]]
62
+ # then
63
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
64
+ # fi
65
+
66
+ # If you use bundler, this might be useful to you:
67
+ # if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
68
+ # then
69
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
70
+ # gem install bundler
71
+ # fi
72
+ # if [[ -s Gemfile ]] && command -v bundle
73
+ # then
74
+ # bundle install
75
+ # fi
76
+
77
+ if [[ $- == *i* ]] # check for interactive shells
78
+ then
79
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
80
+ else
81
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
82
+ fi
83
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in email_list.gemspec
4
+ gemspec
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "email_list/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "email_list"
7
+ s.version = EmailList::VERSION
8
+ s.authors = ["Michael Guterl"]
9
+ s.email = ["michael@diminishing.org"]
10
+ s.homepage = "http://github.com/recruitmilitary/email_list"
11
+ s.summary = %q{A gem for managing a list of email addresses stored in a string.}
12
+ s.description = %q{A gem for managing a list of email addresses stored in a string.}
13
+
14
+ s.rubyforge_project = "email_list"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency "rspec"
22
+ end
@@ -0,0 +1,61 @@
1
+ require "email_list/version"
2
+
3
+ class EmailList
4
+
5
+ EMAIL_ADDRESS_QTEXT = Regexp.new '[^\\x0d\\x22\\x5c\\x80-\\xff]', nil, 'n'
6
+ EMAIL_ADDRESS_DTEXT = Regexp.new '[^\\x0d\\x5b-\\x5d\\x80-\\xff]', nil, 'n'
7
+ EMAIL_ADDRESS_ATOM = Regexp.new '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+', nil, 'n'
8
+ EMAIL_ADDRESS_QUOTED_PAIR = Regexp.new '\\x5c[\\x00-\\x7f]', nil, 'n'
9
+ EMAIL_ADDRESS_DOMAIN_LITERAL = Regexp.new "\\x5b(?:#{EMAIL_ADDRESS_DTEXT}|#{EMAIL_ADDRESS_QUOTED_PAIR})*\\x5d", nil, 'n'
10
+ EMAIL_ADDRESS_QUOTED_STRING = Regexp.new "\\x22(?:#{EMAIL_ADDRESS_QTEXT}|#{EMAIL_ADDRESS_QUOTED_PAIR})*\\x22", nil, 'n'
11
+ EMAIL_ADDRESS_DOMAIN_REF = EMAIL_ADDRESS_ATOM
12
+ EMAIL_ADDRESS_SUB_DOMAIN = "(?:#{EMAIL_ADDRESS_DOMAIN_REF}|#{EMAIL_ADDRESS_DOMAIN_LITERAL})"
13
+ EMAIL_ADDRESS_WORD = "(?:#{EMAIL_ADDRESS_ATOM}|#{EMAIL_ADDRESS_QUOTED_STRING})"
14
+ EMAIL_ADDRESS_DOMAIN = "#{EMAIL_ADDRESS_SUB_DOMAIN}(?:\\x2e#{EMAIL_ADDRESS_SUB_DOMAIN})*"
15
+ EMAIL_ADDRESS_LOCAL_PART = "#{EMAIL_ADDRESS_WORD}(?:\\x2e#{EMAIL_ADDRESS_WORD})*"
16
+ EMAIL_ADDRESS_SPEC = "#{EMAIL_ADDRESS_LOCAL_PART}\\x40#{EMAIL_ADDRESS_DOMAIN}"
17
+ EMAIL_ADDRESS_INNER_PATTERN = Regexp.new "#{EMAIL_ADDRESS_SPEC}", nil, 'n'
18
+ EMAIL_ADDRESS_EXACT_PATTERN = Regexp.new "\\A#{EMAIL_ADDRESS_SPEC}\\z", nil, 'n'
19
+
20
+ def self.valid?(emails)
21
+ split(emails).each do |email|
22
+ unless email =~ EMAIL_ADDRESS_EXACT_PATTERN
23
+ return false
24
+ end
25
+ end
26
+
27
+ true
28
+ end
29
+
30
+ def self.split(emails)
31
+ emails.split(/,|;\s?/).map &:strip
32
+ end
33
+
34
+ include Enumerable
35
+
36
+ attr_reader :emails
37
+
38
+ def initialize(string)
39
+ string = '' if string.nil?
40
+
41
+ @string = string
42
+ @emails = EmailList.split(@string)
43
+ end
44
+
45
+ def each(&block)
46
+ @emails.each(&block)
47
+ end
48
+
49
+ def to_s
50
+ @string.to_s
51
+ end
52
+
53
+ def ==(other)
54
+ if other.is_a?(String)
55
+ emails.sort == EmailList.split(other).sort
56
+ else
57
+ emails.sort == other.emails.sort
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,3 @@
1
+ class EmailList
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,104 @@
1
+ require 'email_list'
2
+
3
+ describe EmailList do
4
+
5
+ describe '.valid?' do
6
+ it 'returns true for a single email address' do
7
+ EmailList.valid?('foo@example.com').should be_true
8
+ end
9
+
10
+ it 'returns false for a blank string' do
11
+ EmailList.valid?(' ').should be_false
12
+ end
13
+
14
+ it 'returns false for a bad email' do
15
+ EmailList.valid?('foo').should be_false
16
+ end
17
+
18
+ it 'returns false when one email in a list is invalid' do
19
+ EmailList.valid?('foo@example.com, foo@').should be_false
20
+ end
21
+
22
+ it 'returns true for a comma separated list of email addresses' do
23
+ EmailList.valid?('foo@example.com,bar@example.com').should be_true
24
+ end
25
+
26
+ it 'returns true for a comma separated (with spaces) list of email addresses' do
27
+ EmailList.valid?('foo@example.com, bar@example.com').should be_true
28
+ end
29
+
30
+ it 'returns true for a comma separated (with multiple spaces) list of email addresses' do
31
+ EmailList.valid?('foo@example.com, bar@example.com').should be_true
32
+ end
33
+
34
+ it 'returns true for a semi-colon separated list of email addresses' do
35
+ EmailList.valid?('foo@example.com;bar@example.com').should be_true
36
+ end
37
+
38
+ it 'returns true for a semi-colon separated (with spaces) list of email addresses' do
39
+ EmailList.valid?('foo@example.com; bar@example.com').should be_true
40
+ end
41
+
42
+ it 'returns true for a semi-colon separated (with multiple spaces) list of email addresses' do
43
+ EmailList.valid?('foo@example.com; bar@example.com').should be_true
44
+ end
45
+ end
46
+
47
+ describe '.split' do
48
+ it 'returns a one element array for a single email address' do
49
+ EmailList.split('foo@example.org').should == ['foo@example.org']
50
+ end
51
+
52
+ it 'returns an array of email addresses for a comma separated list' do
53
+ EmailList.split('foo@example.org,bar@example.org').should == ['foo@example.org', 'bar@example.org']
54
+ end
55
+
56
+ it 'returns an array of email addresses for a comma separated (with spaces) list' do
57
+ EmailList.split('foo@example.org, bar@example.org').should == ['foo@example.org', 'bar@example.org']
58
+ end
59
+
60
+ it 'returns an array of email addresses for a semi-colon separated list' do
61
+ EmailList.split('foo@example.org;bar@example.org').should == ['foo@example.org', 'bar@example.org']
62
+ end
63
+
64
+ it 'returns an array of email addresses for a semi-colon separated (with spaces) list' do
65
+ EmailList.split('foo@example.org; bar@example.org').should == ['foo@example.org', 'bar@example.org']
66
+ end
67
+ end
68
+
69
+ describe '#to_s' do
70
+ it 'returns the original string' do
71
+ string = 'foo@example.org, bar@example.org'
72
+ email_list = EmailList.new(string)
73
+
74
+ email_list.to_s.should == string
75
+ end
76
+ end
77
+
78
+ it 'behaves like an enumerable' do
79
+ email_list = EmailList.new('foo@example.org, bar@example.org')
80
+
81
+ email_list.map.should == ['foo@example.org', 'bar@example.org']
82
+ end
83
+
84
+ it 'compares against other instances of EmailList' do
85
+ email_list1 = EmailList.new('foo@example.org, bar@example.org')
86
+ email_list2 = EmailList.new('bar@example.org, foo@example.org')
87
+
88
+ email_list1.should == email_list2
89
+ email_list2.should == email_list1
90
+ end
91
+
92
+ it 'compares against strings' do
93
+ string = 'foo@example.org, bar@example.org'
94
+ email_list = EmailList.new(string)
95
+
96
+ email_list.should == string
97
+ end
98
+
99
+ it 'returns an empty email list when given nil' do
100
+ email_list = EmailList.new(nil)
101
+
102
+ email_list.emails.should == []
103
+ end
104
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: email_list
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Michael Guterl
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-02-27 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: A gem for managing a list of email addresses stored in a string.
35
+ email:
36
+ - michael@diminishing.org
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - .gitignore
45
+ - .rvmrc
46
+ - Gemfile
47
+ - Rakefile
48
+ - email_list.gemspec
49
+ - lib/email_list.rb
50
+ - lib/email_list/version.rb
51
+ - spec/email_list_spec.rb
52
+ homepage: http://github.com/recruitmilitary/email_list
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project: email_list
81
+ rubygems_version: 1.8.15
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: A gem for managing a list of email addresses stored in a string.
85
+ test_files:
86
+ - spec/email_list_spec.rb