self-defense 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/self-defense.rb +29 -0
- metadata +55 -0
data/lib/self-defense.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# file: self-defense.rb
|
4
|
+
|
5
|
+
class SelfDefense
|
6
|
+
|
7
|
+
@@hits = [Time.now - 1]
|
8
|
+
|
9
|
+
def initialize(&block)
|
10
|
+
super()
|
11
|
+
@unit = {s: proc{|x| x}, m: proc{|x| x*60}, h: proc{|x| x*60*60}}
|
12
|
+
yield(self)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.new
|
16
|
+
super()
|
17
|
+
@@hits << Time.now
|
18
|
+
end
|
19
|
+
|
20
|
+
def rapid?(recovery_period=0.8)
|
21
|
+
(Time.now - @@hits.last) > recovery_period
|
22
|
+
end
|
23
|
+
|
24
|
+
def sustained?(h={})
|
25
|
+
duration = @unit[h[:duration].slice!(-1).to_sym].call(h[:duration])
|
26
|
+
@@hits.select {|x| @@hits.last - x <= duration.to_i}.length < h[:hit_limit]
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: self-defense
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors: []
|
7
|
+
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-07-07 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/self-defense.rb
|
26
|
+
has_rdoc: true
|
27
|
+
homepage:
|
28
|
+
licenses: []
|
29
|
+
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.3.5
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: self-defense
|
54
|
+
test_files: []
|
55
|
+
|