Class: Cardigan::Command::AddTransitions

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entry, io) ⇒ AddTransitions

Returns a new instance of AddTransitions.



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

def initialize entry, io
  @entry, @io = entry, io
  @usage = '<start status> [<subsequent status>]+'
  @help = 'Creates 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/add_transitions.rb', line 4

def help
  @help
end

#usageObject (readonly)

Returns the value of attribute usage.



4
5
6
# File 'lib/cardigan/command/add_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
25
26
# File 'lib/cardigan/command/add_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
  @entry[name] ||= []
  states = states.uniq
  @entry[name] += states
  states.each {|state| @entry[state] ||= [] }
end