class Audiothority::Change
Public Class Methods
new(field, choices, tags)
click to toggle source
# File lib/audiothority/change.rb, line 5 def initialize(field, choices, tags) @field = field @choices = choices @tags = tags end
Public Instance Methods
perform()
click to toggle source
# File lib/audiothority/change.rb, line 11 def perform if performable? @tags.each do |tag| tag.send(tag_setter, value) end end end
present(display)
click to toggle source
# File lib/audiothority/change.rb, line 19 def present(display) if performable? ignored = @choices.reject { |k, _| k == value } ignored = ignored.map do |v, c| %("#{display.set_color(v, :red)}" (#{c})) end chosen = %("#{display.set_color(value, :green)}" (#{@choices[value]})) table = ignored.map do |i| [display.set_color(@field, :yellow), i, '~>', chosen] end display.print_table(table, indent: 2) end end
Private Instance Methods
majority?()
click to toggle source
# File lib/audiothority/change.rb, line 47 def majority? @choices.values[-2..-1].uniq.size == 2 end
performable?()
click to toggle source
# File lib/audiothority/change.rb, line 43 def performable? @choices.any? && (@choices.one? || majority?) end
tag_setter()
click to toggle source
# File lib/audiothority/change.rb, line 35 def tag_setter @tag_setter ||= (@field.to_s + '=').to_sym end
value()
click to toggle source
# File lib/audiothority/change.rb, line 39 def value @value ||= @choices.keys.last end