Class: Cardigan::CardEditor

Inherits:
Object
  • Object
show all
Defined in:
lib/cardigan/card_editor.rb

Instance Method Summary collapse

Constructor Details

#initialize(card, io) ⇒ CardEditor

Returns a new instance of CardEditor.



3
4
5
# File 'lib/cardigan/card_editor.rb', line 3

def initialize card, io
  @card, @io = card, io
end

Instance Method Details

#set(key, value) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cardigan/card_editor.rb', line 7

def set key, value
  return if key == 'id'
  value = '' unless value
  if value.empty?
    if @card[key]
      @io.say "removing #{key} from '#{@card['id']}'"
      @card.delete key
    end
  else
    unless @card[key] == value
      @io.say "changing #{key} from '#{@card[key]}' to '#{value}' for '#{@card['id']}'"
      @card[key] = value
    end
  end
end