Class: BlogSchemaExtractor

Inherits:
BaseService show all
Defined in:
app/services/blog_schema_extractor.rb

Overview

Service object: blog schema extractor.

Instance Attribute Summary collapse

Attributes inherited from BaseService

#options

Instance Method Summary collapse

Methods inherited from BaseService

#log_debug, #log_warning, #logger, #tagged_logger

Constructor Details

#initialize(article, options = {}) ⇒ BlogSchemaExtractor

Returns a new instance of BlogSchemaExtractor.

Parameters:

  • article (Post)

    the blog article to extract schemas from

  • options (Hash) (defaults to: {})

    service options (see BaseService#initialize)

Options Hash (options):

  • model (String)

    LLM model id (defaults to the :blog_extraction registry role)



9
10
11
12
13
# File 'app/services/blog_schema_extractor.rb', line 9

def initialize(article, options = {})
  @article = article
  @model = options[:model].presence || AiModelConstants.id(:blog_extraction)
  super(options)
end

Instance Attribute Details

#articleObject (readonly)

Returns the value of attribute article.



4
5
6
# File 'app/services/blog_schema_extractor.rb', line 4

def article
  @article
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'app/services/blog_schema_extractor.rb', line 4

def model
  @model
end

#resultObject (readonly)

Returns the value of attribute result.



4
5
6
# File 'app/services/blog_schema_extractor.rb', line 4

def result
  @result
end

Instance Method Details

#processObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/services/blog_schema_extractor.rb', line 15

def process
  log_info "Processing schema extraction for article #{article.id}: #{article.subject}"

  @result = extract_schema_content
  save_schema_markup if @result[:schemas].present?

  # Always update the timestamp to mark that extraction was attempted
  # This prevents the same articles from being processed repeatedly
  update_extraction_timestamp

  @result
end