Class: AwesomeChatgptActors::CastControl
- Inherits:
-
Object
- Object
- AwesomeChatgptActors::CastControl
- Defined in:
- lib/awesome_chatgpt_actors/cast_control.rb
Overview
This class is responsible to control the actors csv file
Class Method Summary collapse
- .actor_exist?(actor: nil) ⇒ Boolean
- .actor_exist_in_pt?(actor: nil) ⇒ Boolean
- .actors ⇒ Object
- .actors_csv ⇒ Object
- .actors_pt ⇒ Object
- .actors_pt_csv ⇒ Object
- .add_actor(actor: nil, prompt: nil, has_placeholder: false, accertivity: 1, default_frequency: 0, default_presence: 0, language: "en") ⇒ Object
- .csv_path ⇒ Object
- .pt_csv_path ⇒ Object
- .remove_actor(actor: nil, language: "en") ⇒ Object
- .temp_path ⇒ Object
Class Method Details
.actor_exist?(actor: nil) ⇒ Boolean
57 58 59 60 61 62 63 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 57 def self.actor_exist?(actor: nil) raise "The actor is nil" if actor.nil? raise "The csv file does not exist" unless File.exist?(csv_path) act_column_to_array = actors_csv.map { |row| row["act"] } act_column_to_array.include? actor end |
.actor_exist_in_pt?(actor: nil) ⇒ Boolean
65 66 67 68 69 70 71 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 65 def self.actor_exist_in_pt?(actor: nil) raise "The actor is nil" if actor.nil? raise "The csv file does not exist" unless File.exist?(pt_csv_path) act_column_to_array = actors_pt_csv.map { |row| row["act"] } act_column_to_array.include? actor end |
.actors ⇒ Object
30 31 32 33 34 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 30 def self.actors raise "The csv file does not exist" unless File.exist?(csv_path) actors_csv.map { |row| row["act"] }.uniq end |
.actors_csv ⇒ Object
18 19 20 21 22 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 18 def self.actors_csv raise "The csv file does not exist" unless File.exist?(csv_path) @actors_csv = CSV.read(csv_path, headers: true, quote_char: '"', col_sep: ",", row_sep: :auto) end |
.actors_pt ⇒ Object
36 37 38 39 40 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 36 def self.actors_pt raise "The csv file does not exist" unless File.exist?(pt_csv_path) actors_pt_csv.map { |row| row["act"] }.uniq end |
.actors_pt_csv ⇒ Object
24 25 26 27 28 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 24 def self.actors_pt_csv raise "The csv file does not exist" unless File.exist?(pt_csv_path) @actors_pt_csv = CSV.read(pt_csv_path, headers: true, quote_char: '"', col_sep: ",", row_sep: :auto) end |
.add_actor(actor: nil, prompt: nil, has_placeholder: false, accertivity: 1, default_frequency: 0, default_presence: 0, language: "en") ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 42 def self.add_actor(actor: nil, prompt: nil, has_placeholder: false, accertivity: 1, default_frequency: 0, default_presence: 0, language: "en") file_path = csv_path if language == "en" file_path = pt_csv_path if language == "pt" raise "The actor is nil" if actor.nil? raise "The prompt is nil" if prompt.nil? raise "File path is nil" if file_path.nil? raise "The csv file does not exist" unless File.exist?(file_path) raise "The actor already exists" if actor_exist?(actor: actor) CSV.open(file_path, "a", headers: true, quote_char: '"', col_sep: ",", force_quotes: true) do |csv| csv << [actor, prompt, has_placeholder, accertivity, default_frequency, default_presence] end end |
.csv_path ⇒ Object
6 7 8 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 6 def self.csv_path ENV.fetch("CAST_CSV_NAME", "prompts-data/awesome-en-prompts.csv") end |
.pt_csv_path ⇒ Object
10 11 12 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 10 def self.pt_csv_path ENV.fetch("CAST_PT_CSV_NAME", "prompts-data/awesome-pt-prompts.csv") end |
.remove_actor(actor: nil, language: "en") ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 73 def self.remove_actor(actor: nil, language: "en") file_path = csv_path if language == "en" file_path = pt_csv_path if language == "pt" raise "The actor is nil" if actor.nil? raise "File path is nil" if file_path.nil? raise "The csv file does not exist" unless File.exist?(file_path) (raise "The actor does not exist" unless actor_exist?(actor: actor)) if language == "en" (raise "The actor does not exist" unless actor_exist_in_pt?(actor: actor)) if language == "pt" actors_csv.delete_if { |row| row["act"] == actor } if language == "en" actors_pt_csv.delete_if { |row| row["act"] == actor } if language == "pt" CSV.open(temp_path, "w", headers: true, quote_char: '"', col_sep: ",", force_quotes: true) do |csv| csv << %w[act prompt has_placeholder accertivity default_frequency default_presence] actors_csv.each { |row| csv << row unless row["act"] == actor } if language == "en" actors_pt_csv.each { |row| csv << row unless row["act"] == actor } if language == "pt" end FileUtils.mv(temp_path, file_path) end |
.temp_path ⇒ Object
14 15 16 |
# File 'lib/awesome_chatgpt_actors/cast_control.rb', line 14 def self.temp_path ENV.fetch("CAST_TEMP_NAME", "temp.csv") end |