ablab 0.4.0 → 0.4.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa8125e2a869a953786f4b1bcacab2ac1752d00c
4
- data.tar.gz: c661d695bcad5f817801b42aa1e4ffc99920d346
3
+ metadata.gz: 286428614a6e48db6263c90b9d93e6b21f135d1d
4
+ data.tar.gz: e09c47ce77cd92c10e795f104fdd4b8396711438
5
5
  SHA512:
6
- metadata.gz: 7f459d5d133435d8c828d0626c0846575c3eb49d941fb21bb430cb1c91853162f5ff82fe89c2c49df0e2ace5eafcc1eba65adcd05865e6e84fcb875de792848d
7
- data.tar.gz: 2a9e3c91a04cec5ee3691604b806dce7b53c4cf3871ee1dea791033326f16f0be0f13475ac507f4ece116e858adedf0537fbbb645baaaf671e33a8204587ca88
6
+ metadata.gz: fd4c37fd7af9a3ca1296bb22b54566e0e9b13e76e50e3eb04d07a9621e9d37e25cbcccbd548b8f27ec90493d2ebd326312072746c197be99886332fe54461f6b
7
+ data.tar.gz: 9d04f20ea5dd676cd71a07aed0cb76648fa1a38ff84407d89b8d91e191daa96df569911f4f3e447cfe7db884cd948cc7c81ad598d31944a35ae7c436e22c72b8
@@ -76,7 +76,7 @@ module Ablab
76
76
 
77
77
  def initialize(name, &block)
78
78
  @name = name.to_sym
79
- @control = Group.control
79
+ @control = Group.new(:control, 'control group')
80
80
  @groups = [@control]
81
81
  @callbacks = []
82
82
  instance_exec(&block)
@@ -147,7 +147,7 @@ module Ablab
147
147
  t += group.weight / tot_weight
148
148
  break group if d < t
149
149
  t
150
- end
150
+ end.try(:name)
151
151
  end
152
152
 
153
153
  def draw
@@ -171,7 +171,7 @@ module Ablab
171
171
  return nil unless request && request.respond_to?(:params)
172
172
  groups = parse_groups(request.params[:ablab_group])
173
173
  group = groups[experiment.name.to_s]
174
- experiment.groups.find { |g| g == group }
174
+ group.to_sym if group && experiment.groups.map { |g| g.name.to_s }.include?(group)
175
175
  end
176
176
 
177
177
  private def parse_groups(str)
@@ -202,39 +202,11 @@ module Ablab
202
202
 
203
203
  class Group
204
204
  attr_reader :name, :description, :weight
205
- alias_method :eql?, :==
205
+
206
206
  def initialize(name, description = nil, weight = nil)
207
207
  @name, @description = name.to_sym, description
208
208
  @weight = weight || 1
209
209
  end
210
-
211
- def control?
212
- name == :control
213
- end
214
-
215
- def experimental?
216
- !control?
217
- end
218
-
219
- def ==(o)
220
- if o.is_a?(Symbol)
221
- name == o
222
- elsif o.is_a?(String)
223
- name.to_s == o
224
- elsif o.is_a?(self.class)
225
- name == o.name && description == o.description
226
- else
227
- false
228
- end
229
- end
230
-
231
- def hash
232
- name.hash
233
- end
234
-
235
- def self.control
236
- new(:control, 'control group')
237
- end
238
210
  end
239
211
 
240
212
  class Result
@@ -1,3 +1,3 @@
1
1
  module Ablab
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -248,14 +248,13 @@ describe Ablab do
248
248
 
249
249
  describe "#group" do
250
250
  it "returns one of the groups" do
251
- expect([:a, :b, :control]).to include(Ablab::Run.new(experiment, rand(12345).to_s, request).group)
251
+ expect(Ablab::Run.new(experiment, rand(12345).to_s, request).group).to be_in([:a, :b, :control])
252
252
  end
253
253
 
254
254
  it "returns the forced group, if set with the 'ablab_group' param" do
255
255
  params = { ablab_group: 'bar:baz,foo:a' }
256
256
  allow(request).to receive(:params).and_return(params)
257
257
  run = Ablab::Run.new(experiment, '6q5wed', request)
258
- expect(run.group).to be_a(Ablab::Group)
259
258
  expect(run.group).to eq(:a)
260
259
  end
261
260
  end
@@ -358,51 +357,4 @@ describe Ablab do
358
357
  end
359
358
  end
360
359
  end
361
-
362
- describe Ablab::Group do
363
- let(:control_group) { Ablab::Group.new(:control, "control group") }
364
- let(:experimental_group) { Ablab::Group.new(:foo, "foo group") }
365
-
366
- describe "#control?" do
367
- it 'is true for the control group' do
368
- expect(control_group.control?).to be true
369
- end
370
-
371
- it 'is false for other groups' do
372
- expect(experimental_group.control?).to be false
373
- end
374
- end
375
-
376
- describe "#experimental?" do
377
- it 'is false for the control group' do
378
- expect(control_group.experimental?).to be false
379
- end
380
-
381
- it 'is true for other groups' do
382
- expect(experimental_group.experimental?).to be true
383
- end
384
- end
385
-
386
- describe "#==" do
387
- it 'accepts comparison to Symbol instances' do
388
- expect(control_group).to eq(:control)
389
- expect(control_group).not_to eq(:foo)
390
- end
391
-
392
- it 'accepts comparison to String instances' do
393
- expect(control_group).to eq('control')
394
- expect(control_group).not_to eq('foo')
395
- end
396
-
397
- it 'accepts comparison to Ablab::Group instances' do
398
- expect(control_group).to eq(control_group)
399
- expect(control_group).to eq(Ablab::Group.new(:control, "control group"))
400
- expect(control_group).not_to eq(experimental_group)
401
- end
402
-
403
- it 'is false for everyhing else' do
404
- expect(control_group).not_to eq(Object.new)
405
- end
406
- end
407
- end
408
360
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ablab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Ongaro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-18 00:00:00.000000000 Z
11
+ date: 2016-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails