go-rank 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.0.5 2009-01-10
2
+
3
+ * 1 enhancement:
4
+ * added methods for comparing Ranks (<,>,==,!=)
5
+
1
6
  == 0.0.4 2008-12-31
2
7
 
3
8
  * 1 minor enhancement:
data/Rakefile CHANGED
@@ -39,13 +39,13 @@ RUBYFORGE_PROJECT = 'go-rank' # The unix name for your project
39
39
  HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
40
40
  DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
41
41
 
42
- NAME = "gorank"
42
+ NAME = "go-rank"
43
43
  REV = nil
44
44
  # UNCOMMENT IF REQUIRED:
45
45
  # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
46
46
  VERS = Gorank::VERSION::STRING + (REV ? ".#{REV}" : "")
47
47
  CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
48
- RDOC_OPTS = ['--quiet', '--title', 'gorank documentation',
48
+ RDOC_OPTS = ['--quiet', '--title', 'go-rank documentation',
49
49
  "--opname", "index.html",
50
50
  "--line-numbers",
51
51
  "--main", "README",
data/lib/gorank/gorank.rb CHANGED
@@ -2,44 +2,44 @@
2
2
  class GoRank
3
3
 
4
4
  @@rank_array = [
5
- '7 dan',
6
- '6 dan',
7
- '5 dan',
8
- '4 dan',
9
- '3 dan',
10
- '2 dan',
11
- '1 dan',
12
- '1 kyu',
13
- '2 kyu',
14
- '3 kyu',
15
- '4 kyu',
16
- '5 kyu',
17
- '6 kyu',
18
- '7 kyu',
19
- '8 kyu',
20
- '9 kyu',
21
- '10 kyu',
22
- '11 kyu',
23
- '12 kyu',
24
- '13 kyu',
25
- '14 kyu',
26
- '15 kyu',
27
- '16 kyu',
28
- '17 kyu',
29
- '18 kyu',
30
- '19 kyu',
31
- '20 kyu',
32
- '21 kyu',
33
- '22 kyu',
34
- '23 kyu',
35
- '24 kyu',
36
- '25 kyu',
37
- '26 kyu',
38
- '27 kyu',
39
- '28 kyu',
40
- '29 kyu',
41
- '30 kyu',
42
- ]
5
+ '7 dan',
6
+ '6 dan',
7
+ '5 dan',
8
+ '4 dan',
9
+ '3 dan',
10
+ '2 dan',
11
+ '1 dan',
12
+ '1 kyu',
13
+ '2 kyu',
14
+ '3 kyu',
15
+ '4 kyu',
16
+ '5 kyu',
17
+ '6 kyu',
18
+ '7 kyu',
19
+ '8 kyu',
20
+ '9 kyu',
21
+ '10 kyu',
22
+ '11 kyu',
23
+ '12 kyu',
24
+ '13 kyu',
25
+ '14 kyu',
26
+ '15 kyu',
27
+ '16 kyu',
28
+ '17 kyu',
29
+ '18 kyu',
30
+ '19 kyu',
31
+ '20 kyu',
32
+ '21 kyu',
33
+ '22 kyu',
34
+ '23 kyu',
35
+ '24 kyu',
36
+ '25 kyu',
37
+ '26 kyu',
38
+ '27 kyu',
39
+ '28 kyu',
40
+ '29 kyu',
41
+ '30 kyu',
42
+ ]
43
43
 
44
44
  # valid values for kd: :kyu, :dan
45
45
  def initialize(num, kd)
@@ -47,7 +47,7 @@ class GoRank
47
47
  @num = num
48
48
  @kd = kd
49
49
  raise ArgumentError if @kd == :kyu and (@num < 1 or @num > 30) or
50
- @kd == :dan and (@num < 1 or @num > 7)
50
+ @kd == :dan and (@num < 1 or @num > 7)
51
51
  end
52
52
 
53
53
  # human representation of a rank.
@@ -100,4 +100,17 @@ class GoRank
100
100
  }
101
101
  result
102
102
  end
103
+
104
+ def <(other)
105
+ other-self > 0
106
+ end
107
+
108
+ def >(other)
109
+ other-self < 0
110
+ end
111
+
112
+ def ==(other)
113
+ other-self == 0
114
+ end
115
+
103
116
  end # class GoRank
@@ -2,7 +2,7 @@ module Gorank #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 4
5
+ TINY = 5
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/test/test_gorank.rb CHANGED
@@ -145,4 +145,20 @@ p myrank
145
145
  rank = GoRank.new 31, :kyu
146
146
  }
147
147
  end
148
+
149
+ def test_order_of_ranks
150
+ assert GoRank.new(5,:kyu) < GoRank.new(4,:kyu)
151
+ assert GoRank.new(4,:kyu) > GoRank.new(5,:kyu)
152
+
153
+ assert GoRank.new(1,:dan) > GoRank.new(1,:kyu)
154
+ assert GoRank.new(1,:kyu) < GoRank.new(1,:dan)
155
+
156
+ assert GoRank.new(2,:dan) > GoRank.new(30,:kyu)
157
+ assert GoRank.new(30,:kyu) < GoRank.new(1,:dan)
158
+
159
+ assert GoRank.new(5,:dan) == GoRank.new(5,:dan)
160
+ assert GoRank.new(5,:kyu) == GoRank.new(5,:kyu)
161
+
162
+ assert GoRank.new(1,:kyu) != GoRank.new(2,:kyu)
163
+ end
148
164
  end
data/website/index.html CHANGED
@@ -5,7 +5,7 @@
5
5
  <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
6
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
7
  <title>
8
- gorank
8
+ go-rank
9
9
  </title>
10
10
  <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
11
  <style>
@@ -30,18 +30,68 @@
30
30
  <body>
31
31
  <div id="main">
32
32
 
33
- <h1>gorank</h1>
33
+ <h1>go-rank</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/gorank"; return false'>
35
35
  <p>Get Version</p>
36
36
  <a href="http://rubyforge.org/projects/gorank" class="numbers">0.0.4</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
- <p>Go-Rank is a class for handling ranks in the game of <a href="http://en.wikipedia.org/wiki/Go_(game">Go</a>)</p>
39
+ <p>Go-Rank is a class for handling ranks in the game of <a href="http://en.wikipedia.org/wiki/Go_(game)">Go</a>.</p>
40
40
  <h2>Installing</h2>
41
- <pre syntax="ruby">sudo gem install gorank</pre>
41
+ <pre syntax="ruby">sudo gem install go-rank</pre>
42
42
  <h2>The basics</h2>
43
43
  <h2>Demonstration of usage</h2>
44
- <p>See the rdoc documentation of this gem.</p>
44
+ <pre syntax="ruby">
45
+ require 'rubygems'
46
+ require 'gorank'
47
+
48
+ # create a go-rank object
49
+ rank = GoRank.new 30, :kyu # 30 kyu is the lowest
50
+ # 7 dan is the highest rank
51
+
52
+ puts rank.to_s # =&gt; '30 kyu'
53
+
54
+ # one level higher:
55
+
56
+ rank += 1
57
+ puts rank.to_s # =&gt; '29 kyu'
58
+
59
+
60
+ # one level lower:
61
+
62
+ rank -= 1
63
+ puts rank.to_s # =&gt; '30 kyu'
64
+
65
+ # cannot go lower:
66
+ begin
67
+ rank -= 1 # =&gt; raises IndexError
68
+ puts rank.to_s
69
+ rescue
70
+ #
71
+ end
72
+
73
+ # change from kyu to dan rank
74
+
75
+ rank = GoRank.new 1, :kyu
76
+ puts rank.to_s # =&gt; '1 kyu'
77
+ rank += 1
78
+ puts rank.to_s # =&gt; '1 dan'
79
+ rank += 1
80
+ puts rank.to_s # =&gt; '2 dan'
81
+
82
+ # difference between two ranks
83
+
84
+ rank1 = GoRank.new 1, :dan
85
+ rank2 = GoRank.new 5, :kyu
86
+
87
+ puts "difference between #{rank1} and #{rank2} is #{rank1-rank2} stones"
88
+ # =&gt; "difference between 1 dan and 5 kyu is 5 stones"
89
+
90
+ # invalid ranks
91
+
92
+ rank = GoRank.new 35, :kyu # =&gt; raises ArgumentError
93
+ </pre>
94
+
45
95
  <h2>Forum</h2>
46
96
  <p><a href="http://groups.google.com/group/gorank">http://groups.google.com/group/gorank</a></p>
47
97
  <h2>How to submit patches</h2>
data/website/index.txt CHANGED
@@ -1,20 +1,76 @@
1
- h1. gorank
1
+ h1. go-rank
2
2
 
3
3
  h2. What
4
4
 
5
- Go-Rank is a class for handling ranks in the game of "Go":http://en.wikipedia.org/wiki/Go_(game)
5
+ Go-Rank is a class for handling ranks in the game of ["Go":http://en.wikipedia.org/wiki/Go_(game)].
6
6
 
7
7
  h2. Installing
8
8
 
9
- <pre syntax="ruby">sudo gem install gorank</pre>
9
+ <pre syntax="ruby">sudo gem install go-rank</pre>
10
10
 
11
11
  h2. The basics
12
12
 
13
13
 
14
14
  h2. Demonstration of usage
15
15
 
16
- See the rdoc documentation of this gem.
16
+ <pre syntax="ruby">
17
+ require 'rubygems'
18
+ require 'gorank'
17
19
 
20
+ # create a go-rank object
21
+ rank = GoRank.new 30, :kyu # 30 kyu is the lowest
22
+ # 7 dan is the highest rank
23
+
24
+ puts rank.to_s # => '30 kyu'
25
+
26
+ # one level higher:
27
+
28
+ rank += 1
29
+ puts rank.to_s # => '29 kyu'
30
+
31
+
32
+ # one level lower:
33
+
34
+ rank -= 1
35
+ puts rank.to_s # => '30 kyu'
36
+
37
+ # cannot go lower:
38
+ begin
39
+ rank -= 1 # => raises IndexError
40
+ puts rank.to_s
41
+ rescue
42
+ #
43
+ end
44
+
45
+ # change from kyu to dan rank
46
+
47
+ rank = GoRank.new 1, :kyu
48
+ puts rank.to_s # => '1 kyu'
49
+ rank += 1
50
+ puts rank.to_s # => '1 dan'
51
+ rank += 1
52
+ puts rank.to_s # => '2 dan'
53
+
54
+ # difference between two ranks
55
+
56
+ rank1 = GoRank.new 1, :dan
57
+ rank2 = GoRank.new 5, :kyu
58
+
59
+ puts "difference between #{rank1} and #{rank2} is #{rank1-rank2} stones"
60
+ # => "difference between 1 dan and 5 kyu is 5 stones"
61
+
62
+ # comparing ranks
63
+ # a better rank is greater than a lower rank
64
+
65
+ puts GoRank.new(1,:dan) > GoRank(5,:kyu) # => true
66
+ puts GoRank.new(1,:dan) == GoRank(1,:dan) # => true
67
+ puts GoRank.new(1,:dan) < GoRank(5,:kyu) # => false
68
+
69
+ # invalid ranks
70
+
71
+ rank = GoRank.new 35, :kyu # => raises ArgumentError
72
+ </pre>
73
+
18
74
  h2. Forum
19
75
 
20
76
  "http://groups.google.com/group/gorank":http://groups.google.com/group/gorank
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go-rank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Preymesser
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-12-31 00:00:00 +01:00
12
+ date: 2009-01-10 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency