Class: SpreeMenuChat::ContentBuilder

Inherits:
Object
  • Object
show all
Defined in:
app/services/spree_menu_chat/content_builder.rb

Overview

Builds the plain-text chunk that actually gets embedded for one source record. Kept separate from ReembedProductJob/ReembedCatalogJob so the "what text represents this record" question has one answer, checked once by SpreeMenuChat::Embedding#content_hash_for to decide whether a re-embed is even necessary.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(embeddable) ⇒ ContentBuilder

Returns a new instance of ContentBuilder.



12
13
14
# File 'app/services/spree_menu_chat/content_builder.rb', line 12

def initialize(embeddable)
  @embeddable = embeddable
end

Class Method Details

.call(embeddable) ⇒ Object



8
9
10
# File 'app/services/spree_menu_chat/content_builder.rb', line 8

def self.call(embeddable)
  new(embeddable).call
end

Instance Method Details

#callObject



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

def call
  case @embeddable
  when Spree::Product
    product_content
  when Spree::Policy
    policy_content
  else
    raise ArgumentError, "SpreeMenuChat::ContentBuilder doesn't know how to embed a #{@embeddable.class}"
  end
end