-
Notifications
You must be signed in to change notification settings - Fork 0
/
cod_input_update.rb
52 lines (45 loc) · 1.48 KB
/
cod_input_update.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
module CoDInputUpdate
### UPDATE ###
def set_update_state(input=nil)
if @people.count == 0 && @state != :update # if the update takes the count to zero, don't trigger this code
set_menu_state
@response = "There is no one to update."
return
end
@state = :update_person
@response = "Update a person."
@state_instructions = "Type the name of a person to update. Esc to exit."
end
def set_update_person_state(input)
# escape quites update
if(input == "\e")
set_menu_state
@response = "Update quit."
elsif (@people[input])
@person = @people[input]
@people.delete(@person.name)
@person.name = nil
(@person.is_a? CoDPolitician) ? @person.party = nil : @person.politics = nil
@response = "Updating #{input}."
@state_instructions = "Enter new name. Leave blank to randomize the person."
@state = :update_person_name
else
@response = "No one is named '#{input}'."
end
end
def set_update_person_name_state(input)
process_naming(input)
@state = :update_person_partisanization unless @person.name.nil?
end
def set_update_person_partisanization(input)
process_partisanization(input)
# the person will be set to nil and the state set to :menu if the partisanization is successful
if @person.nil?
# replace the last instance of "created" with "updated"
# TODO: this would probably be clearer with a regex, unfortunately there's no rsub
@response.reverse!
@response.sub!("detaerc","detadpu")
@response.reverse!
end
end
end