Class: Crm::ArticleRevisionDiffRowComponent::DataValues

Inherits:
Object
  • Object
show all
Defined in:
app/components/crm/article_revision_diff_row_component/data_values.rb

Overview

Resolves stored Article revision data to stable keys and reviewer-facing labels.

Constant Summary collapse

BOOLEAN_FIELDS =

Fields whose values are booleans and render as "Yes" / "No".

Returns:

  • (Array<Symbol>)
%i[sales support warranty_labor warranty_parts].freeze

Instance Method Summary collapse

Constructor Details

#initialize(field:, current:, proposed:) ⇒ DataValues

Returns a new instance of DataValues.

Parameters:

  • field (Symbol, String)

    the revision data field being diffed

  • current (Object, Array)

    the value of the field in the current revision

  • proposed (Object, Array)

    the value of the field in the proposed revision



12
13
14
15
16
# File 'app/components/crm/article_revision_diff_row_component/data_values.rb', line 12

def initialize(field:, current:, proposed:)
  @field = field.to_sym
  @current = current
  @proposed = proposed
end

Instance Method Details

#to_aArray<Hash{String => String}>

Resolves the current and proposed values into keyed hashes of labels.

Returns:

  • (Array<Hash{String => String}>)

    the labeled current and proposed values



20
21
22
23
24
25
26
27
28
29
# File 'app/components/crm/article_revision_diff_row_component/data_values.rb', line 20

def to_a
  case field
  when :product_line_ids then record_values(ProductLine)
  when :product_category_ids then record_values(ProductCategory)
  when :item_ids then record_values(Item)
  when :tags then [current, proposed].map { |values| Array(values).index_with(&:to_s) }
  when :content_links then content_link_values
  else scalar_values
  end
end