skills_cards_validations 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 47aa9d2d6d81ac5f6d1dc0d58bd7c781e4ee4f28e5b09620be910f9aef93c0fd
4
+ data.tar.gz: 4265563852537d02e77aaa2d7628caa308964c72b82d33d5f0ad2bb77963c315
5
+ SHA512:
6
+ metadata.gz: 74cd91b66c7777a74013030d1f646ba5f6bfeabbcb3a887f05973ee9ef7b4eab9b5a06f2992bb1ea49c6c6b3dac584f4390e65a5b67b6a6354ebc026cfad0e39
7
+ data.tar.gz: 950733862854a5d25800c7c23eccab3fc308eda5031b4da75f44e721e2a93f27747cf4af9043a90033cf7d34102c6a12ab6c997fa0ea4e8226af03d5e2acf75f
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in skills_cards_validator.gemspec
6
+ gemspec
@@ -0,0 +1,22 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ skills_cards_validations (1.5.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.11.3)
10
+ rake (10.5.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ bundler (~> 1.16)
17
+ minitest (~> 5.0)
18
+ rake (~> 10.0)
19
+ skills_cards_validations!
20
+
21
+ BUNDLED WITH
22
+ 1.16.6
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Tyler Brothers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,84 @@
1
+ # Skills Cards Validations
2
+
3
+ Defines the skills cards data model and methods to validate whether given data matches this model.
4
+
5
+ This gem allows different projects to have a shared way of determining whether data is a skills card and whether it is valid.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'skills_cards_validations'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install skills_cards_validations
22
+
23
+ ## Usage
24
+
25
+ Be sure to completely exit and re-open your running rails app or console.
26
+
27
+ Card and Data validation using the provided Validator class:
28
+ ```ruby
29
+ v = SkillsCardsValidations::Validator.new
30
+ v.id? 1234
31
+ # => #<Valid:0x0123>
32
+ v.id?(1234).result
33
+ # => true
34
+ v.id?(1234).original
35
+ # => 1
36
+
37
+ v.id? 123456
38
+ # => #<Invalid:0x0124>
39
+ v.id?(123456).result
40
+ # => false
41
+ v.id?(12345).original
42
+ # => 123456
43
+ ```
44
+
45
+ You can also create your own class and use the provided mixins.
46
+
47
+ ```ruby
48
+ class MyCardValidator
49
+ include SkillsCardsValidations::CardValidations
50
+
51
+ def initialize(record)
52
+ @record = record
53
+ end
54
+
55
+ def id?
56
+ super(@record[:my_id])
57
+ end
58
+ end
59
+
60
+ v = MyCardValidator.new({
61
+ my_id: 1234
62
+ })
63
+
64
+ v.id?
65
+ # => #<Valid:0x0123>
66
+ v.id?.result
67
+ # => true
68
+ v.id?.original
69
+ # => 1
70
+ ```
71
+
72
+ ## Development
73
+
74
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
75
+
76
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags.
77
+
78
+ ## Contributing
79
+
80
+ Bug reports and pull requests are welcome on GitHub at https://bitbucket.org/utahyouthvillage/skillscardsvalidations.
81
+
82
+ ## License
83
+
84
+ TBD
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "skills_cards_validator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require "skills_cards_validations/version"
2
+ require "skills_cards_validations/card_validations"
3
+ require "skills_cards_validations/data_validations"
4
+
5
+ module SkillsCardsValidations
6
+ class Validator
7
+ include CardValidations
8
+ include DataValidations
9
+ end
10
+ end
@@ -0,0 +1,128 @@
1
+ require "skills_cards_validations/valid"
2
+ require "skills_cards_validations/invalid"
3
+ require "time"
4
+
5
+ module SkillsCardsValidations
6
+ module CardValidations
7
+ def id?(id)
8
+ # A 4 to 5 digit number, 0-9.
9
+ # But! No leading 0
10
+ if id_has_leading_zero?(id)
11
+ return Invalid.new(id)
12
+ elsif id.to_s.length == 4 || id.to_s.length == 5
13
+ return Valid.new(id)
14
+ end
15
+ Invalid.new(id)
16
+ end
17
+
18
+ def id_has_leading_zero?(id)
19
+ if (id).to_s[0] == "0"
20
+ return true
21
+ end
22
+ return false
23
+ end
24
+
25
+ def system?(sy)
26
+ # 1 - 4
27
+ if sy.to_i.between? 1, 4
28
+ return Valid.new(sy)
29
+ end
30
+ Invalid.new(sy)
31
+ end
32
+
33
+ def point_range?(pr)
34
+ # 1 - 3
35
+ if pr.to_i.between? 1, 3
36
+ return Valid.new(pr)
37
+ end
38
+ Invalid.new(pr)
39
+ end
40
+
41
+ def bond_range?(br)
42
+ # 1 - 4
43
+ if br.to_i.between? 1, 4
44
+ return Valid.new(br)
45
+ end
46
+ Invalid.new(br)
47
+ end
48
+
49
+ def card_number?(cn)
50
+ # 1 - 3
51
+ if cn.to_i.between? 1, 3
52
+ return Valid.new(cn)
53
+ end
54
+ Invalid.new(cn)
55
+ end
56
+
57
+ def date?(d)
58
+ # 'YYYY-MM-DD'
59
+ begin
60
+ Time.parse(d.to_s)
61
+ return Valid.new(d)
62
+ rescue ArgumentError, NoMethodError
63
+ end
64
+ Invalid.new(d)
65
+ end
66
+
67
+ def date_has_valid_month?(d)
68
+ # 'YYYY-MM-DD'
69
+ begin
70
+ month = d.to_s.split('-')[1]
71
+ return month.to_i >= 1 && month.to_i <= 12
72
+ rescue ArgumentError
73
+ return false
74
+ end
75
+ end
76
+
77
+ def date_has_valid_day?(d)
78
+ # 'YYYY-MM-DD'
79
+ # Depends on also having a valid month and year!
80
+ begin
81
+ if date_has_valid_month?(d) && date_has_valid_year?(d)
82
+ day = d.to_s.split('-')[2]
83
+ return day.to_i > 0 && day.to_i < 32
84
+ end
85
+ rescue ArgumentError
86
+ end
87
+ return false
88
+ end
89
+
90
+ def date_has_valid_year?(d)
91
+ # 'YYYY-MM-DD'
92
+ begin
93
+ year = d.to_s.split('-')[0]
94
+ return year.to_i >= 1000
95
+ rescue ArgumentError
96
+ return false
97
+ end
98
+ end
99
+
100
+ def date_is_after_today?(d)
101
+ # 'YYYY-MM-DD'
102
+ begin
103
+ return Time.parse(d.to_s).to_date > Time.now.to_date
104
+ rescue ArgumentError
105
+ return false
106
+ end
107
+ end
108
+
109
+ def date_is_before_last_year?(d)
110
+ # 'YYYY-MM-DD'
111
+ begin
112
+ now = Time.now.to_date
113
+ last_year = Date.civil(now.year-1, now.month, now.day)
114
+ return Time.parse(d.to_s).to_date < last_year
115
+ rescue ArgumentError
116
+ return false
117
+ end
118
+ end
119
+
120
+ def privileges?(pr)
121
+ # True or False
122
+ if pr.to_s.downcase == "true" || pr.to_s.downcase == "false"
123
+ return Valid.new(pr)
124
+ end
125
+ Invalid.new(pr)
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,109 @@
1
+ require "skills_cards_validations/valid"
2
+ require "skills_cards_validations/invalid"
3
+
4
+ module SkillsCardsValidations
5
+ module DataValidations
6
+ def line?(l)
7
+ # 1 - 23
8
+ if l.to_i.between?(1, 23)
9
+ return Valid.new(l)
10
+ end
11
+ Invalid.new(l)
12
+ end
13
+
14
+ def skill?(s)
15
+ # 0 - 99
16
+ if s.to_i > 0 && s.to_i < 100
17
+ return Valid.new(s)
18
+ end
19
+ Invalid.new(s)
20
+ end
21
+
22
+ def positive_correction?(pc)
23
+ # True or False
24
+ if pc.to_s.downcase == 'true' || pc.to_s.downcase == 'false' || pt.to_s == ''
25
+ return Valid.new(pc)
26
+ end
27
+ Invalid.new(pc)
28
+ end
29
+
30
+ def interaction_sign?(is)
31
+ # +, -
32
+ if is.to_s == '+' || is.to_s == '-'
33
+ return Valid.new(is)
34
+ end
35
+ Invalid.new(is)
36
+ end
37
+
38
+ def pc_and_is?(pc, is)
39
+ # Positive Correction and Interaction Sign.
40
+ # If PC is filled out, IS must be +
41
+ # PC cannot be filled out when IS is -
42
+ if pc.to_s.downcase == 'true' && is.to_s == '+'
43
+ return Valid.new([pc, is])
44
+ elsif pc.to_s.downcase == 'false' && (is.to_s == '+' || is.to_s == '-')
45
+ return Valid.new([pc, is])
46
+ end
47
+ Invalid.new([pc, is])
48
+ end
49
+
50
+ def interaction?(is)
51
+ # S, A, I
52
+ if is.to_s == 'S' || is.to_s == 'A' || is.to_s == 'I'
53
+ return Valid.new(is)
54
+ end
55
+ Invalid.new(is)
56
+ end
57
+
58
+ def provider?(pr)
59
+ # A combinational logic representing a pattern
60
+ # of bubbling the skills card a certain way.
61
+ # The first two bubbles (FT1 and FT2, e.g. 1 and 2)
62
+ # cannot be combined with any of the other bubbles
63
+ # (A1 - A4, e.g. 3 - 6).
64
+ if pr.to_i.between?(1, 6) ||
65
+ pr.to_i.between?(34, 36) ||
66
+ pr.to_i.between?(45, 46) ||
67
+ pr.to_i == 56
68
+ return Valid.new(pr)
69
+ end
70
+ Invalid.new(pr)
71
+ end
72
+
73
+ def ft_one_and_others_filled_out?(provider)
74
+ if provider.to_s.split('').first == "1" && provider.to_s.length > 1
75
+ return Valid.new(provider)
76
+ end
77
+ Invalid.new(provider)
78
+ end
79
+
80
+ def ft_two_and_others_filled_out?(provider)
81
+ if provider.to_s.split('').first == "2" && provider.to_s.length > 1
82
+ return Valid.new(provider)
83
+ end
84
+ Invalid.new(provider)
85
+ end
86
+
87
+ def more_than_two_providers_filled_out?(provider)
88
+ if provider.to_s.length > 2
89
+ return Valid.new(provider)
90
+ end
91
+ Invalid.new(provider)
92
+ end
93
+
94
+ def preventative_teaching?(pt)
95
+ # True or False
96
+ if pt.to_s.downcase == 'true' || pt.to_s.downcase == 'false' || pt.to_s == ''
97
+ return Valid.new(pt)
98
+ end
99
+ Invalid.new(pt)
100
+ end
101
+
102
+ def pt_and_is_and_pc?(pt, is, pc)
103
+ if pt.to_s.downcase == 'true' && is.to_s == '+' && pc.to_s.downcase != 'true'
104
+ return Valid.new([pt, is, pc])
105
+ end
106
+ Invalid.new([pt, is, pc])
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'validation'
2
+
3
+ class Invalid < Validation
4
+ def initialize(data)
5
+ super(data, false)
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require_relative 'validation'
2
+
3
+ class Valid < Validation
4
+ def initialize(data)
5
+ super(data, true)
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ class Validation
2
+ attr_reader :original
3
+ attr_reader :result
4
+
5
+ def initialize(data, result)
6
+ @original = data
7
+ @result = result
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module SkillsCardsValidations
2
+ VERSION = "1.5.0"
3
+ end
@@ -0,0 +1,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "skills_cards_validations/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "skills_cards_validations"
8
+ spec.version = SkillsCardsValidations::VERSION
9
+ spec.authors = ["Tyler Brothers"]
10
+ spec.email = ["tbrothers@youthvillage.org"]
11
+
12
+ spec.summary = %q{Defines the skills cards data model and methods to validate whether given data matches this model.}
13
+ spec.homepage = "https://bitbucket.org/utahyouthvillage/skillscardsvalidator"
14
+ spec.license = "TBD"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: skills_cards_validations
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.0
5
+ platform: ruby
6
+ authors:
7
+ - Tyler Brothers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-04-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description:
56
+ email:
57
+ - tbrothers@youthvillage.org
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - lib/skills_cards_validations.rb
71
+ - lib/skills_cards_validations/card_validations.rb
72
+ - lib/skills_cards_validations/data_validations.rb
73
+ - lib/skills_cards_validations/invalid.rb
74
+ - lib/skills_cards_validations/valid.rb
75
+ - lib/skills_cards_validations/validation.rb
76
+ - lib/skills_cards_validations/version.rb
77
+ - skills_cards_validations.gemspec
78
+ homepage: https://bitbucket.org/utahyouthvillage/skillscardsvalidator
79
+ licenses:
80
+ - TBD
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.7.7
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Defines the skills cards data model and methods to validate whether given
102
+ data matches this model.
103
+ test_files: []