Module: Split::DashboardHelpers

Defined in:
lib/split/dashboard/helpers.rb

Instance Method Summary collapse

Instance Method Details

#confidence_level(z_score) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/split/dashboard/helpers.rb', line 28

def confidence_level(z_score)
  return z_score if z_score.is_a? String

  z = round(z_score.to_s.to_f, 3).abs

  if z >= 2.58
    '99% confidence'
  elsif z >= 1.96
    '95% confidence'
  elsif z >= 1.65
    '90% confidence'
  else
    'Insufficient confidence'
  end

end

#h(text) ⇒ Object



4
5
6
# File 'lib/split/dashboard/helpers.rb', line 4

def h(text)
  Rack::Utils.escape_html(text)
end

#number_to_percentage(number, precision = 2) ⇒ Object



16
17
18
# File 'lib/split/dashboard/helpers.rb', line 16

def number_to_percentage(number, precision = 2)
  round(number * 100)
end

#path_prefixObject



12
13
14
# File 'lib/split/dashboard/helpers.rb', line 12

def path_prefix
  request.env['SCRIPT_NAME']
end

#round(number, precision = 2) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/split/dashboard/helpers.rb', line 20

def round(number, precision = 2)
  begin
    BigDecimal(number.to_s)
  rescue ArgumentError
    BigDecimal(0)
  end.round(precision).to_f
end

#url(*path_parts) ⇒ Object



8
9
10
# File 'lib/split/dashboard/helpers.rb', line 8

def url(*path_parts)
  [ path_prefix, path_parts ].join("/").squeeze('/')
end