ohio_state_person 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in OhioStatePerson.gemspec
4
+ gemspec
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "OhioStatePerson/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ohio_state_person"
7
+ s.version = OhioStatePerson::VERSION
8
+ s.authors = ["mikegee"]
9
+ s.email = ["gee.24@osu.edu"]
10
+ s.homepage = "https://github.com/ASCTech/OhioStatePerson"
11
+ s.summary = %q{ActiveRecord mixin for people at Ohio State University}
12
+ s.description = %q{requires fields: name_n, emplid; sets id to emplid.to_i; provides a search method; etc.}
13
+
14
+ s.rubyforge_project = "OhioStatePerson"
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
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ s.add_runtime_dependency "activerecord", '~> 3.0'
25
+ end
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module OhioStatePerson
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,54 @@
1
+ require "OhioStatePerson/version"
2
+
3
+ module OhioStatePerson
4
+
5
+ def self.included(base)
6
+ base.instance_eval do
7
+ validates_uniqueness_of :name_n
8
+ validates_format_of :name_n, :with => /\A[a-z]([a-z-]*[a-z])?\.[1-9]\d*\z/, :message => 'must be in format: name.#'
9
+
10
+ validates_uniqueness_of :emplid
11
+ validates_format_of :emplid, :with => /\A\d{8,9}\z/, :message => 'must be 8 or 9 digits'
12
+
13
+ before_validation :set_id, :on => :create
14
+ validate :id_is_emplid
15
+
16
+
17
+ def self.search(q)
18
+ q.strip! if q
19
+ case q
20
+ when /\A\d+\z/
21
+ where(:emplid => q)
22
+ when /\A\D+\.\d+\z/
23
+ where(:name_n => q)
24
+ when /(\S+),\s*(\S+)/
25
+ where('last_name LIKE ? AND first_name LIKE ?', $1, "#{$2}%")
26
+ when /(\S+)\s+(\S+)/
27
+ where('first_name LIKE ? AND last_name LIKE ?', $1, "#{$2}%")
28
+ when /\S/
29
+ where('last_name LIKE ?', "#{q}%")
30
+ else
31
+ where('1=2')
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+
38
+ def email
39
+ name_n.present? ? "#{name_n}@osu.edu" : ''
40
+ end
41
+
42
+ protected
43
+
44
+ def set_id
45
+ self.id = self.emplid.to_i
46
+ end
47
+
48
+ def id_is_emplid
49
+ unless self.id == self.emplid.to_i
50
+ errors.add(:id, 'must be the same as the emplid')
51
+ end
52
+ end
53
+
54
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ohio_state_person
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
+ - mikegee
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-21 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: activerecord
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 7
29
+ segments:
30
+ - 3
31
+ - 0
32
+ version: "3.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: "requires fields: name_n, emplid; sets id to emplid.to_i; provides a search method; etc."
36
+ email:
37
+ - gee.24@osu.edu
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - .gitignore
46
+ - Gemfile
47
+ - OhioStatePerson.gemspec
48
+ - Rakefile
49
+ - lib/OhioStatePerson.rb
50
+ - lib/OhioStatePerson/version.rb
51
+ homepage: https://github.com/ASCTech/OhioStatePerson
52
+ licenses: []
53
+
54
+ post_install_message:
55
+ rdoc_options: []
56
+
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ requirements: []
78
+
79
+ rubyforge_project: OhioStatePerson
80
+ rubygems_version: 1.8.10
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: ActiveRecord mixin for people at Ohio State University
84
+ test_files: []
85
+