pebbles-anti_hangover 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,6 @@
1
+ === 0.1.0 / 2011-08-18
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/pebbles/anti_hangover.rb
6
+ spec/spec_helper.rb
7
+ spec/anti_hangover_spec.rb
8
+ autotest/discover.rb
data/README.txt ADDED
@@ -0,0 +1,49 @@
1
+ = pebbles-anti_hangover
2
+
3
+ * https://github.com/kwappa/pebbles-anti_hangover
4
+
5
+ == DESCRIPTION:
6
+
7
+ * 体重と睡眠時間、種類から「二日酔いせずに飲める酒量」を計算します。
8
+ * http://www.nikkeibp.co.jp/archives/347/347655.html
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * (あとでかく)
13
+
14
+ == SYNOPSIS:
15
+
16
+ (あとでかく)
17
+
18
+ == REQUIREMENTS:
19
+
20
+ * pebbles
21
+
22
+ == INSTALL:
23
+
24
+ * gem install pebbles-anti_hangover
25
+
26
+ == LICENSE:
27
+
28
+ (The MIT License)
29
+
30
+ Copyright (c) 2011 SHIOYA, Hiromu
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining
33
+ a copy of this software and associated documentation files (the
34
+ 'Software'), to deal in the Software without restriction, including
35
+ without limitation the rights to use, copy, modify, merge, publish,
36
+ distribute, sublicense, and/or sell copies of the Software, and to
37
+ permit persons to whom the Software is furnished to do so, subject to
38
+ the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be
41
+ included in all copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
44
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
46
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
47
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
48
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
49
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ # -*- ruby -*-
3
+ Encoding.default_external = Encoding.find("UTF-8")
4
+
5
+ require 'rubygems'
6
+ require 'hoe'
7
+
8
+ Hoe.spec 'pebbles-anti_hangover' do
9
+ developer('SHIOYA, Hiromu', 'kwappa.856@gmail.com')
10
+ extra_deps << ['pebbles', '>= 0']
11
+ end
@@ -0,0 +1,2 @@
1
+ # -*- coding: utf-8 -*-
2
+ Autotest.add_discovery { "rspec2" }
@@ -0,0 +1,96 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'pebbles'
3
+
4
+ class Pebbles::AntiHangover
5
+ VERSION = '0.1.0'
6
+
7
+ ALCOHOL_TYPE = {
8
+ beer: {
9
+ name: 'ビール',
10
+ glass: 'レギュラー缶',
11
+ unit: '本',
12
+ alcoholicity: 5,
13
+ net: 350,
14
+ },
15
+ chuhi: {
16
+ name: '酎ハイ',
17
+ glass: 'サワーグラス',
18
+ unit: '杯',
19
+ alcoholicity: 7,
20
+ net: 200,
21
+ },
22
+ sake: {
23
+ name: '日本酒',
24
+ glass: '小徳利',
25
+ unit: '本',
26
+ alcoholicity: 12,
27
+ net: 180,
28
+ },
29
+ wine: {
30
+ name: 'ワイン',
31
+ glass: 'ワイングラス',
32
+ unit: '杯',
33
+ alcoholicity: 15,
34
+ net: 120,
35
+ },
36
+ shochu: {
37
+ name: '焼酎',
38
+ glass: '焼酎グラス',
39
+ unit: '杯',
40
+ alcoholicity: 25,
41
+ net: 60,
42
+ },
43
+ whiskey: {
44
+ name: 'ウイスキー',
45
+ glass: 'ショットグラス',
46
+ unit: '杯',
47
+ alcoholicity: 40,
48
+ net: 40,
49
+ },
50
+ }
51
+
52
+ def initialize drunker_weight, drinking_hours
53
+ @drunker_weight = drunker_weight
54
+ @drinking_hours = drinking_hours
55
+ raise ArgumentError unless @drunker_weight > 0
56
+ raise ArgumentError unless @drinking_hours > 0
57
+ @drunk_glasses = Hash[ALCOHOL_TYPE.keys.zip(Array.new(ALCOHOL_TYPE.count).fill(0))]
58
+ end
59
+
60
+ def permissible_alcohol
61
+ (15 * @drunker_weight * @drinking_hours / 80).round
62
+ end
63
+
64
+ def drink kind, glasses = 1
65
+ raise ArgumentError unless ALCOHOL_TYPE.include?(kind)
66
+ @drunk_glasses[kind] += glasses
67
+ end
68
+
69
+ def total_drunk
70
+ @drunk_glasses.inject(0) do |total, drunk|
71
+ glass = ALCOHOL_TYPE[drunk.first]
72
+ total + (drunk.last * glass[:alcoholicity] * glass[:net] / 100.0).round
73
+ end
74
+ end
75
+
76
+ def hangover?
77
+ total_drunk > permissible_alcohol
78
+ end
79
+
80
+ def dump
81
+ result = "体重#{@drunker_weight}kgのあなたは、\n"
82
+ drunk_logs = ''
83
+ @drunk_glasses.each do |kind, glasses|
84
+ drunk_logs += "、\n" unless drunk_logs.empty?
85
+ glass = ALCOHOL_TYPE[kind]
86
+ drunk_logs += "#{glass[:name]}を#{glass[:glass]}に#{glasses}#{glass[:unit]}"
87
+ end
88
+ percentage = (total_drunk.to_f / permissible_alcohol.to_f * 1000.0).floor / 10.0
89
+ result += drunk_logs + "飲んで、\n#{@drinking_hours}時間後に起きなければなりません。\n\n"
90
+ result += 'そのときあなたは、おそらく二日酔いに'
91
+ result += "#{hangover? ? 'なる' : 'ならない'}でしょう。\n\n"
92
+ result += "(許容量の#{percentage}%を飲んでいます)\n"
93
+
94
+ result
95
+ end
96
+ end
@@ -0,0 +1,119 @@
1
+ # -*- coding: utf-8 -*-
2
+ require File.join(File.dirname(__FILE__), 'spec_helper')
3
+
4
+ describe AntiHangover do
5
+ # コンストラクタ
6
+ # 体重と起きるまでの時間を受け取る
7
+ # 総摂取可能アルコール量(ml)を算出
8
+ describe '#initialize' do
9
+ context '64kg drunker wakes 8hour later' do
10
+ subject { @anti_hangover = AntiHangover.new(64, 8) }
11
+ its(:permissible_alcohol) { should == 96 }
12
+ end
13
+
14
+ context 'minus weight given' do
15
+ specify do
16
+ expect { @anti_hangover = AntiHangover.new(-1, 8) }.to raise_error ArgumentError
17
+ end
18
+ end
19
+
20
+ context 'minus hours given' do
21
+ specify do
22
+ expect { @anti_hangover = AntiHangover.new(64, -1) }.to raise_error ArgumentError
23
+ end
24
+ end
25
+ end
26
+
27
+ # 飲む : 種類と数を渡して今まで飲んだ数を返す
28
+ describe '#drink' do
29
+ before do
30
+ @anti_hangover = AntiHangover.new(75, 8)
31
+ end
32
+
33
+ context 'drink first beer' do
34
+ subject { @anti_hangover.drink :beer }
35
+ it { should == 1 }
36
+ end
37
+
38
+ context 'drink second beer' do
39
+ before { @anti_hangover.drink :beer }
40
+ subject { @anti_hangover.drink :beer }
41
+ it { should == 2 }
42
+ end
43
+
44
+ context 'drunk 3 sake' do
45
+ subject { @anti_hangover.drink :sake, 3 }
46
+ it { should == 3 }
47
+ end
48
+
49
+ context 'drunk unknown alcohol' do
50
+ specify do
51
+ expect { @anti_hangover.drink :unknwon_alcohol }.to raise_error ArgumentError
52
+ end
53
+ end
54
+ end
55
+
56
+ # 現在までに飲んだアルコールの総量を返す (ml)
57
+ describe '#total_drunk' do
58
+ before do
59
+ @anti_hangover = AntiHangover.new(75, 8)
60
+ end
61
+
62
+ context 'drunk beer, beer, sake, wine' do
63
+ before do
64
+ @anti_hangover.drink :beer, 2
65
+ @anti_hangover.drink :sake
66
+ @anti_hangover.drink :wine
67
+ end
68
+ subject { @anti_hangover.total_drunk }
69
+ it { should == 35 + 22 + 18 }
70
+ end
71
+ end
72
+
73
+ # 二日酔いするかどうかを返す
74
+ describe '#hangover?' do
75
+ before do
76
+ @anti_hangover = AntiHangover.new(64, 8)
77
+ end
78
+ context 'without drinking' do
79
+ subject { @anti_hangover.hangover? }
80
+ it { should be_false }
81
+ end
82
+ context 'too much drinking' do
83
+ before do
84
+ @anti_hangover.drink :beer # 17.5
85
+ @anti_hangover.drink :chuhi # 14.0
86
+ @anti_hangover.drink :sake # 21.6
87
+ @anti_hangover.drink :wine # 18.0
88
+ @anti_hangover.drink :shochu # 15.0
89
+ @anti_hangover.drink :whiskey # 16.0
90
+ end
91
+ subject { @anti_hangover.hangover? }
92
+ it { should be_true }
93
+ end
94
+ end
95
+
96
+ describe '#dump' do
97
+ before do
98
+ @anti_hangover = AntiHangover.new(64, 8)
99
+ end
100
+
101
+ context 'without drinking' do
102
+ subject { r = @anti_hangover.dump ; puts r ; r }
103
+ it { should be_instance_of String }
104
+ end
105
+
106
+ context 'after too much drinking' do
107
+ before do
108
+ @anti_hangover.drink :beer, 0 # 17.5
109
+ @anti_hangover.drink :chuhi, 2 # 14.0
110
+ @anti_hangover.drink :sake # 21.6
111
+ @anti_hangover.drink :wine, 3 # 18.0
112
+ @anti_hangover.drink :shochu, 12 # 15.0
113
+ @anti_hangover.drink :whiskey, 1 # 16.0
114
+ end
115
+ subject { r = @anti_hangover.dump ; puts r ; r }
116
+ it { should be_instance_of String }
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'rspec'
3
+ $: << File.join(File.dirname(File.dirname(__FILE__)), 'lib')
4
+
5
+ require 'pebbles/anti_hangover'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pebbles-anti_hangover
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - SHIOYA, Hiromu
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-20 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: pebbles
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: hoe
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: "2.10"
35
+ type: :development
36
+ version_requirements: *id002
37
+ description: "* \xE4\xBD\x93\xE9\x87\x8D\xE3\x81\xA8\xE7\x9D\xA1\xE7\x9C\xA0\xE6\x99\x82\xE9\x96\x93\xE3\x80\x81\xE7\xA8\xAE\xE9\xA1\x9E\xE3\x81\x8B\xE3\x82\x89\xE3\x80\x8C\xE4\xBA\x8C\xE6\x97\xA5\xE9\x85\x94\xE3\x81\x84\xE3\x81\x9B\xE3\x81\x9A\xE3\x81\xAB\xE9\xA3\xB2\xE3\x82\x81\xE3\x82\x8B\xE9\x85\x92\xE9\x87\x8F\xE3\x80\x8D\xE3\x82\x92\xE8\xA8\x88\xE7\xAE\x97\xE3\x81\x97\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82\n * http://www.nikkeibp.co.jp/archives/347/347655.html"
38
+ email:
39
+ - kwappa.856@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files:
45
+ - History.txt
46
+ - Manifest.txt
47
+ - README.txt
48
+ files:
49
+ - History.txt
50
+ - Manifest.txt
51
+ - README.txt
52
+ - Rakefile
53
+ - lib/pebbles/anti_hangover.rb
54
+ - spec/spec_helper.rb
55
+ - spec/anti_hangover_spec.rb
56
+ - autotest/discover.rb
57
+ - .gemtest
58
+ homepage: https://github.com/kwappa/pebbles-anti_hangover
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options:
63
+ - --main
64
+ - README.txt
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project: pebbles-anti_hangover
82
+ rubygems_version: 1.8.5
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: "* \xE4\xBD\x93\xE9\x87\x8D\xE3\x81\xA8\xE7\x9D\xA1\xE7\x9C\xA0\xE6\x99\x82\xE9\x96\x93\xE3\x80\x81\xE7\xA8\xAE\xE9\xA1\x9E\xE3\x81\x8B\xE3\x82\x89\xE3\x80\x8C\xE4\xBA\x8C\xE6\x97\xA5\xE9\x85\x94\xE3\x81\x84\xE3\x81\x9B\xE3\x81\x9A\xE3\x81\xAB\xE9\xA3\xB2\xE3\x82\x81\xE3\x82\x8B\xE9\x85\x92\xE9\x87\x8F\xE3\x80\x8D\xE3\x82\x92\xE8\xA8\x88\xE7\xAE\x97\xE3\x81\x97\xE3\x81\xBE\xE3\x81\x99\xE3\x80\x82 * http://www.nikkeibp.co.jp/archives/347/347655.html"
86
+ test_files: []
87
+