Class: Audiothority::Change

Inherits:
Object
  • Object
show all
Defined in:
lib/audiothority/change.rb

Direct Known Subclasses

RewriteChange

Instance Method Summary collapse

Constructor Details

#initialize(field, choices, tags) ⇒ Change

Returns a new instance of Change.



5
6
7
8
9
# File 'lib/audiothority/change.rb', line 5

def initialize(field, choices, tags)
  @field = field
  @choices = choices
  @tags = tags
end

Instance Method Details

#performObject



11
12
13
14
15
16
17
# 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) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# 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