Class: UrlAnalyzer
- Inherits:
-
Object
- Object
- UrlAnalyzer
- Defined in:
- lib/scaffolding/url_analyzer.rb
Constant Summary collapse
- INTERACTIVE_TAGS =
%w[input select textarea button].freeze
Instance Attribute Summary collapse
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#page_name ⇒ Object
readonly
Returns the value of attribute page_name.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #analyze ⇒ Object
-
#initialize(url, name_override: nil, ai: false) ⇒ UrlAnalyzer
constructor
rubocop:disable Naming/MethodParameterName.
- #to_h ⇒ Object
Constructor Details
#initialize(url, name_override: nil, ai: false) ⇒ UrlAnalyzer
rubocop:disable Naming/MethodParameterName
11 12 13 14 15 16 17 |
# File 'lib/scaffolding/url_analyzer.rb', line 11 def initialize(url, name_override: nil, ai: false) # rubocop:disable Naming/MethodParameterName @url = url @uri = URI.parse(url) @page_name = name_override || derive_page_name @elements = [] @ai = ai end |
Instance Attribute Details
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
9 10 11 |
# File 'lib/scaffolding/url_analyzer.rb', line 9 def elements @elements end |
#page_name ⇒ Object (readonly)
Returns the value of attribute page_name.
9 10 11 |
# File 'lib/scaffolding/url_analyzer.rb', line 9 def page_name @page_name end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/scaffolding/url_analyzer.rb', line 9 def url @url end |
Instance Method Details
#analyze ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/scaffolding/url_analyzer.rb', line 19 def analyze html = fetch_html if @ai ai_elements = analyze_with_llm(html) @elements = ai_elements if ai_elements end parse_elements(html) if @elements.empty? self end |
#to_h ⇒ Object
29 30 31 |
# File 'lib/scaffolding/url_analyzer.rb', line 29 def to_h { page_name: @page_name, url: @url, url_path: @uri.path, elements: @elements } end |