Class: Equalshares::Params

Inherits:
Object
  • Object
show all
Defined in:
lib/equalshares/params.rb

Overview

Computation parameters. Mirrors the equalSharesParams object from js/main.js and the allowed values wired up in js/interface/formHandler.js.

Constant Summary collapse

TIE_BREAKING_METHODS =
%w[maxVotes minCost maxCost].freeze
COMPLETIONS =
%w[none utilitarian add1 add1e add1u add1eu].freeze
ADD1_OPTIONS =
%w[exhaustive integral].freeze
COMPARISONS =
%w[none satisfaction exclusionRatio].freeze
ACCURACIES =
%w[floats fractions].freeze
SATISFACTIONS =
Satisfaction::NAMES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tie_breaking: [], completion: "add1u", add1_options: %w[exhaustive integral],, comparison: "none", accuracy: "floats", increment: 1, satisfaction: "cost") ⇒ Params

Defaults match js/main.js:6-13. satisfaction selects the MES satisfaction measure (pabutools parity); "cost" is the equalshares.net default.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/equalshares/params.rb', line 18

def initialize(tie_breaking: [], completion: "add1u", add1_options: %w[exhaustive integral],
               comparison: "none", accuracy: "floats", increment: 1, satisfaction: "cost")
  @tie_breaking = Array(tie_breaking)
  @completion = completion
  @add1_options = Array(add1_options)
  @comparison = comparison
  @accuracy = accuracy
  @increment = increment
  @satisfaction = satisfaction
  validate!
end

Instance Attribute Details

#accuracyObject (readonly)

Returns the value of attribute accuracy.



14
15
16
# File 'lib/equalshares/params.rb', line 14

def accuracy
  @accuracy
end

#add1_optionsObject (readonly)

Returns the value of attribute add1_options.



14
15
16
# File 'lib/equalshares/params.rb', line 14

def add1_options
  @add1_options
end

#comparisonObject (readonly)

Returns the value of attribute comparison.



14
15
16
# File 'lib/equalshares/params.rb', line 14

def comparison
  @comparison
end

#completionObject (readonly)

Returns the value of attribute completion.



14
15
16
# File 'lib/equalshares/params.rb', line 14

def completion
  @completion
end

#incrementObject (readonly)

Returns the value of attribute increment.



14
15
16
# File 'lib/equalshares/params.rb', line 14

def increment
  @increment
end

#satisfactionObject (readonly)

Returns the value of attribute satisfaction.



14
15
16
# File 'lib/equalshares/params.rb', line 14

def satisfaction
  @satisfaction
end

#tie_breakingObject (readonly)

Returns the value of attribute tie_breaking.



14
15
16
# File 'lib/equalshares/params.rb', line 14

def tie_breaking
  @tie_breaking
end

Instance Method Details

#add1_option?(name) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/equalshares/params.rb', line 30

def add1_option?(name)
  @add1_options.include?(name)
end