Sha256: 9a1aec3978381aa70d59c6fd702d8a419a793a068b56185b3121570db49a5e6e

Contents?: true

Size: 959 Bytes

Versions: 1

Compression:

Stored size: 959 Bytes

Contents

require 'sinatra/base'
require 'split'
require 'bigdecimal'

module Split
  class Dashboard < Sinatra::Base
    dir = File.dirname(File.expand_path(__FILE__))

    set :views,  "#{dir}/dashboard/views"
    set :public, "#{dir}/dashboard/public"
    set :static, true

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

      def path_prefix
        request.env['SCRIPT_NAME']
      end

      def number_to_percentage(number, precision = 2)
        BigDecimal.new((number * 100).to_s).round(precision).to_f
      end
    end

    get '/' do
      @experiments = Split::Experiment.all
      erb :index
    end

    post '/:experiment' do
      @experiment = Split::Experiment.find(params[:experiment])
      @alternative = Split::Alternative.find(params[:alternative], params[:experiment])
      @experiment.winner = @alternative.name
      @experiment.save
      redirect url('/')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
split-0.1.1 lib/split/dashboard.rb