rasam 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/rasam.rb +105 -9
- data/lib/rasam/version.rb +1 -1
- data/rasam-0.1.0.gem +0 -0
- data/todo.txt +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50ca47f6e35668edc0ed2f243200ea7ca08eb1cc
|
4
|
+
data.tar.gz: 206bb0c8f73de10adb0752e24fe3c489fa3fe342
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25639816cb34e664616860678014049661f00ee9f0446774aaae3452c594722c4476cbdf2645e57dd688f176d398fd4c15f8e9b6366c63b164e0a2ac7ba1cef2
|
7
|
+
data.tar.gz: 97d8b09516f0cde4d7acaa0e5e966079a6e299f051381fd7198a07d75f031182bf0295bb8501478efe505e5ef4f556b82f8f33c59262e64c39a18a272490d230
|
data/README.md
CHANGED
@@ -40,6 +40,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
40
40
|
|
41
41
|
Bug reports and pull requests are welcome on GitHub at https://bitbucket.org/bparanj/rasam.
|
42
42
|
|
43
|
+
gem build rasam.gemspec
|
44
|
+
gem push rasam-0.1.0.gem
|
45
|
+
|
43
46
|
## License
|
44
47
|
|
45
48
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/rasam.rb
CHANGED
@@ -1,23 +1,119 @@
|
|
1
1
|
require "rasam/version"
|
2
|
+
require 'forwardable'
|
2
3
|
|
3
4
|
module Rasam
|
5
|
+
# Value Object
|
6
|
+
# - Pair - Consists of two options
|
7
|
+
# - Choice - Selected option from a given pair
|
8
|
+
# - Criteria - Rationale for the preference. Why the choice was made?
|
9
|
+
class RationalChoice
|
10
|
+
attr_reader :choice, :criteria, :pair
|
11
|
+
|
12
|
+
def initialize(pair, choice, criteria)
|
13
|
+
@choice = choice
|
14
|
+
@criteria = criteria
|
15
|
+
@pair = pair
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
4
20
|
class PairRank
|
5
|
-
|
6
|
-
|
21
|
+
attr_reader :combinations
|
22
|
+
|
23
|
+
def initialize(options)
|
24
|
+
@decisions = []
|
7
25
|
@votes = Hash.new(0)
|
8
|
-
@combinations =
|
26
|
+
@combinations = options.combination(2).to_a
|
27
|
+
end
|
28
|
+
|
29
|
+
def make(rational_choice)
|
30
|
+
@decisions << rational_choice
|
31
|
+
@votes[rational_choice.choice] += 1
|
32
|
+
end
|
33
|
+
|
34
|
+
def score_for(choice)
|
35
|
+
@votes[choice]
|
36
|
+
end
|
37
|
+
|
38
|
+
def rationale_for(choice)
|
39
|
+
decision = @decisions.find{|x| x.choice == choice}
|
40
|
+
decision.criteria
|
41
|
+
end
|
42
|
+
|
43
|
+
def pair_for(choice)
|
44
|
+
decision = @decisions.find{|x| x.choice == choice}
|
45
|
+
decision.pair
|
46
|
+
end
|
47
|
+
|
48
|
+
def tied_pair
|
49
|
+
result = []
|
50
|
+
@combinations.each do |combination|
|
51
|
+
first = score_for(combination[0])
|
52
|
+
second = score_for(combination[1])
|
53
|
+
|
54
|
+
if tie(first, second)
|
55
|
+
result = combination
|
56
|
+
break
|
57
|
+
end
|
58
|
+
end
|
59
|
+
result
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def tie(a, b)
|
65
|
+
a == b
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
class Engine
|
70
|
+
def initialize(options, pair, choice, criteria)
|
71
|
+
@pr = PairRank.new(options)
|
72
|
+
rc = RationalChoice.new(pair, choice, criteria)
|
73
|
+
@pr.make(rc)
|
9
74
|
end
|
10
75
|
|
11
|
-
def
|
12
|
-
@
|
76
|
+
def pair_for(choice)
|
77
|
+
@pr.pair_for(choice)
|
13
78
|
end
|
14
79
|
|
15
|
-
def
|
16
|
-
@
|
80
|
+
def score_for(choice)
|
81
|
+
@pr.score_for(choice)
|
17
82
|
end
|
83
|
+
|
84
|
+
def rationale_for(choice)
|
85
|
+
@pr.rationale_for(choice)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Simulates a complete session
|
90
|
+
class Simulator
|
91
|
+
def initialize(options, choices, criteria)
|
92
|
+
@pr = PairRank.new(options)
|
93
|
+
@choices = choices
|
94
|
+
@criteria = criteria
|
95
|
+
end
|
96
|
+
|
97
|
+
def simulate
|
98
|
+
@pr.combinations.each_with_index do |pair, index|
|
99
|
+
choice = @choices[index]
|
18
100
|
|
19
|
-
|
20
|
-
|
101
|
+
rc = RationalChoice.new(pair, choice, @criteria)
|
102
|
+
@pr.make(rc)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def score_for(choice)
|
107
|
+
@pr.score_for(choice)
|
108
|
+
end
|
109
|
+
|
110
|
+
def tied_pair
|
111
|
+
@pr.tied_pair
|
112
|
+
end
|
113
|
+
|
114
|
+
def break_tie(pair, choice, criteria)
|
115
|
+
rc = RationalChoice.new(pair, choice, criteria)
|
116
|
+
@pr.make(rc)
|
21
117
|
end
|
22
118
|
end
|
23
119
|
end
|
data/lib/rasam/version.rb
CHANGED
data/rasam-0.1.0.gem
ADDED
Binary file
|
data/todo.txt
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bala Paranj
|
@@ -70,7 +70,9 @@ files:
|
|
70
70
|
- bin/setup
|
71
71
|
- lib/rasam.rb
|
72
72
|
- lib/rasam/version.rb
|
73
|
+
- rasam-0.1.0.gem
|
73
74
|
- rasam.gemspec
|
75
|
+
- todo.txt
|
74
76
|
homepage: https://bitbucket.org/bparanj/rasam
|
75
77
|
licenses:
|
76
78
|
- MIT
|