Class: Cardigan::Command::RemoveTransitions

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry, io) ⇒ RemoveTransitions

Returns a new instance of RemoveTransitions.



6
7
8
9
10
# File 'lib/cardigan/command/remove_transitions.rb', line 6

def initialize entry, io
  @entry, @io = entry, io
  @usage = '<start status> [<subsequent status>]+'
  @help = 'Removes transitions from a starting status to a number of subsequent statuses'
end

Instance Attribute Details

#helpObject (readonly)

Returns the value of attribute help.



4
5
6
# File 'lib/cardigan/command/remove_transitions.rb', line 4

def help
  @help
end

#usageObject (readonly)

Returns the value of attribute usage.



4
5
6
# File 'lib/cardigan/command/remove_transitions.rb', line 4

def usage
  @usage
end

Instance Method Details

#execute(text = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cardigan/command/remove_transitions.rb', line 12

def execute text=nil
  unless text and !text.empty?
    @io.say 'missing required start status'
    return
  end
  name, *states = text.scan(/\w+/)
  if states.empty?
    @io.say 'missing required subsequent status'
    return
  end
  name, *states = text.scan(/\w+/)
  @entry[name] -= states
end