rasam 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74c68bc5fcd4b28b309406f7f38c2cf34ed916a5
4
- data.tar.gz: b7558ffc6c126bc2dafb8b04029a898521f8a4a2
3
+ metadata.gz: 50ca47f6e35668edc0ed2f243200ea7ca08eb1cc
4
+ data.tar.gz: 206bb0c8f73de10adb0752e24fe3c489fa3fe342
5
5
  SHA512:
6
- metadata.gz: 94112ea2ad9093a0095b61bbaaa009c4f95a30f9e3a21b6a1cffc9f0cb537d0ed1a3e957634eeddd66ac07a301003df786b503993cc2d7329f8280f77f5d1cb5
7
- data.tar.gz: da5d529758adb53e8ed22c7ec5d1ea433caf20a0afa813abcf3afd8f7151de802a34ea2bca77d4d9804a3367f4f393eb704091f637867b18dc4149dbab4b3425
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
- def initialize(items)
6
- @items = items
21
+ attr_reader :combinations
22
+
23
+ def initialize(options)
24
+ @decisions = []
7
25
  @votes = Hash.new(0)
8
- @combinations = items.combination(2).to_a
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 pair(position)
12
- @combinations[position - 1]
76
+ def pair_for(choice)
77
+ @pr.pair_for(choice)
13
78
  end
14
79
 
15
- def vote(pair, winner)
16
- @votes[winner] += 1
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
- def score_for(item)
20
- @votes[item]
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
@@ -1,3 +1,3 @@
1
1
  module Rasam
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/rasam-0.1.0.gem ADDED
Binary file
data/todo.txt ADDED
@@ -0,0 +1,2 @@
1
+ 1. Use highline library to simulate a user session.
2
+ 2. Update the existing rational choices with the tie break results. This will update the existing decisions array.
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.1.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