Class: ReactToRails::Convert
- Inherits:
-
Object
- Object
- ReactToRails::Convert
- Defined in:
- lib/react_to_rails/convert.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#demo_erb_code ⇒ Object
readonly
Returns the value of attribute demo_erb_code.
-
#erb_template ⇒ Object
readonly
Returns the value of attribute erb_template.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#react_content ⇒ Object
readonly
Returns the value of attribute react_content.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#view_component_ruby_code ⇒ Object
readonly
Returns the value of attribute view_component_ruby_code.
-
#view_component_test_ruby_code ⇒ Object
readonly
Returns the value of attribute view_component_test_ruby_code.
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
- #component_file_name ⇒ Object
-
#initialize(react_content, name:, client: nil) ⇒ Convert
constructor
A new instance of Convert.
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
39 40 41 |
# File 'lib/react_to_rails/convert.rb', line 39 def client @client end |
#demo_erb_code ⇒ Object (readonly)
Returns the value of attribute demo_erb_code.
39 40 41 |
# File 'lib/react_to_rails/convert.rb', line 39 def demo_erb_code @demo_erb_code end |
#erb_template ⇒ Object (readonly)
Returns the value of attribute erb_template.
39 40 41 |
# File 'lib/react_to_rails/convert.rb', line 39 def erb_template @erb_template end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
39 40 41 |
# File 'lib/react_to_rails/convert.rb', line 39 def name @name end |
#react_content ⇒ Object (readonly)
Returns the value of attribute react_content.
39 40 41 |
# File 'lib/react_to_rails/convert.rb', line 39 def react_content @react_content end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
39 40 41 |
# File 'lib/react_to_rails/convert.rb', line 39 def summary @summary end |
#view_component_ruby_code ⇒ Object (readonly)
Returns the value of attribute view_component_ruby_code.
39 40 41 |
# File 'lib/react_to_rails/convert.rb', line 39 def view_component_ruby_code @view_component_ruby_code end |
#view_component_test_ruby_code ⇒ Object (readonly)
Returns the value of attribute view_component_test_ruby_code.
39 40 41 |
# File 'lib/react_to_rails/convert.rb', line 39 def view_component_test_ruby_code @view_component_test_ruby_code end |
Class Method Details
.for_path(path, name:) ⇒ Object
54 55 56 57 |
# File 'lib/react_to_rails/convert.rb', line 54 def self.for_path(path, name:) react_content = File.read(path) new(react_content, name: name) end |
Instance Method Details
#call ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/react_to_rails/convert.rb', line 59 def call puts "### PROMPT ###" puts puts prompt puts puts "Waiting for OpenAI to respond..." response = Client.new.call(prompt) @summary = response.fetch("summary") @view_component_ruby_code = response.fetch("view_component_ruby_code") @erb_template = response.fetch("erb_template") @demo_erb_code = response.fetch("demo_erb_code") @view_component_test_ruby_code = response.fetch("view_component_test_ruby_code") puts @summary return if @erb_template == "" || @view_component_ruby_code == "" puts puts "### EXAMPLE USAGE ###" puts puts @demo_erb_code end |
#component_file_name ⇒ Object
84 85 86 |
# File 'lib/react_to_rails/convert.rb', line 84 def component_file_name @name.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase end |