flirt_checker 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a4c857655e99f960134e2b60deae89cddb09d6ef
4
+ data.tar.gz: fa221bde24dbc79db48342dc30a5320ee9969ac9
5
+ SHA512:
6
+ metadata.gz: d3a783702a0aa66f365357fcd545f46726cf7eb69834f4f7aea4fe011c8428e0048ce70deea53ca767303010af31a4da60577f15e14325810b576b452b28f217
7
+ data.tar.gz: 99940678f7ba0e2460eb75885435d3df0e06cdd19edf7e676bdd41a14b32c22916191f7f344cc767de19a5b8c0285b80a965e409889b1b5727a130c965ceaf02
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ *.gem
15
+ *.swp
16
+ *.save
17
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flirt_checker.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 tacyan
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # FlirtChecker
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'flirt_checker'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install flirt_checker
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/flirt_checker/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/circle.yml ADDED
@@ -0,0 +1,6 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.1.2
4
+ pre:
5
+ - gem install bundler --pre
6
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flirt_checker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flirt_checker"
8
+ spec.version = FlirtChecker::VERSION
9
+ spec.authors = ["tacyan"]
10
+ spec.email = ["tatsuharase@firstserver.co.jp"]
11
+ spec.summary = %q{check flirt by blood type}
12
+ spec.description = %q{check flirt by blood type}
13
+ spec.homepage = "https://github.com/ZCloud-Firstserver/flirt_checker"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,45 @@
1
+ module FlirtChecker
2
+ class Blood
3
+ BLOOD_GROUP = {
4
+ a: ["A","A","A","O"],
5
+ b: ["B","B","B","O"],
6
+ o: ["O","O"],
7
+ ab: ["A","B"]
8
+ }
9
+
10
+ attr_accessor :male, :female, :genotype
11
+
12
+ def initialize(male, female, genotype: false)
13
+ @male = male
14
+ @female = female
15
+ @genotype = genotype
16
+ end
17
+
18
+ def combo
19
+ valid_blood_type?
20
+ collection = BLOOD_GROUP[@male].product(BLOOD_GROUP[@female]).map {|e|
21
+ e.sort.join
22
+ }.uniq
23
+ #phenotype
24
+ collection.map! { |e| to_phenotype(e) } unless @genotype
25
+ collection
26
+ end
27
+
28
+ def combo_with_rate
29
+ valid_blood_type?
30
+ array = BLOOD_GROUP[@male].product(BLOOD_GROUP[@female]).map { |e| e.sort.join }
31
+ hash = array.reduce(Hash.new(0)) { |h,v| h[@genotype ? v : to_phenotype(v)] += 1; h }
32
+ hash.each_with_object({}) { |(k,v), h| h[k] = v.to_f / array.size.to_f }
33
+ end
34
+
35
+ private
36
+
37
+ def to_phenotype(string)
38
+ string[-1] == "O" ? string[0] : string
39
+ end
40
+
41
+ def valid_blood_type?
42
+ raise ArgumentError, "Invalid Blood Type" unless BLOOD_GROUP.key?(@male) && BLOOD_GROUP.key?(@female)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,3 @@
1
+ module FlirtChecker
2
+ VERSION = "0.1.2"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "flirt_checker/version"
2
+ require "flirt_checker/blood"
3
+
4
+ module FlirtChecker
5
+ def self.new(male, female, genotype: false)
6
+ FlirtChecker::Blood.new(male, female, genotype: genotype)
7
+ end
8
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe FlirtChecker do
4
+ it 'has a version number' do
5
+ expect(FlirtChecker::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'returns a combination in phenotype' do
9
+ expected = ["AB", "A", "B", "O"]
10
+ blood = FlirtChecker.new(:a,:b)
11
+ expect(blood.combo).to eql(expected)
12
+ end
13
+
14
+ it 'returns a combination in genotype' do
15
+ expected = ["AB", "AO", "BO", "OO"]
16
+ blood = FlirtChecker.new(:a, :b, genotype: true)
17
+ expect(blood.combo).to eql(expected)
18
+ end
19
+
20
+ it 'returns a combination with rate in phenotype' do
21
+ expected = {"AB"=>0.5625, "A"=>0.1875, "B"=>0.1875, "O"=>0.0625}
22
+ blood = FlirtChecker.new(:a, :b)
23
+ expect(blood.combo_with_rate).to eql(expected)
24
+ end
25
+
26
+ it 'returns a combination with rate in genotype' do
27
+ expected = {"AB"=>0.5625, "AO"=>0.1875, "BO"=>0.1875, "OO"=>0.0625}
28
+ blood = FlirtChecker.new(:a, :b, genotype: true)
29
+ expect(blood.combo_with_rate).to eql(expected)
30
+ end
31
+
32
+ it 'chenges the value of attributes' do
33
+ blood = FlirtChecker.new(:a, :b, genotype: true)
34
+ expect(blood.male = :b).to eql(:b)
35
+ expect(blood.female = :a).to eql(:a)
36
+ expect(blood.genotype = false).to be_falsey
37
+ end
38
+
39
+ it 'raises exception when combo called' do
40
+ blood = FlirtChecker.new(:x, :y)
41
+ expect { blood.combo }.to raise_error(ArgumentError, "Invalid Blood Type")
42
+ end
43
+
44
+ it 'raises exception when combo_with_rate called' do
45
+ blood = FlirtChecker.new(:x, :y)
46
+ expect { blood.combo_with_rate }.to raise_error(ArgumentError, "Invalid Blood Type")
47
+ end
48
+
49
+ it 'does not raise exception when combo called' do
50
+ blood = FlirtChecker.new(:a, :b)
51
+ expect { blood.combo }.not_to raise_error
52
+ end
53
+
54
+ it 'does not raises exception when combo_with_rate called' do
55
+ blood = FlirtChecker.new(:a, :b)
56
+ expect { blood.combo_with_rate }.not_to raise_error
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'flirt_checker'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flirt_checker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - tacyan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-17 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: check flirt by blood type
56
+ email:
57
+ - tatsuharase@firstserver.co.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - circle.yml
70
+ - flirt_checker.gemspec
71
+ - lib/flirt_checker.rb
72
+ - lib/flirt_checker/blood.rb
73
+ - lib/flirt_checker/version.rb
74
+ - spec/flirt_checker_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: https://github.com/ZCloud-Firstserver/flirt_checker
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: check flirt by blood type
100
+ test_files:
101
+ - spec/flirt_checker_spec.rb
102
+ - spec/spec_helper.rb