Class: ProductTaxonomy::Serializers::Attribute::Dist::TxtSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/product_taxonomy/models/serializers/attribute/dist/txt_serializer.rb

Class Method Summary collapse

Class Method Details

.serialize(attribute, padding: 0, locale: "en") ⇒ String

Parameters:

  • attribute (Attribute)
  • padding (Integer) (defaults to: 0)

    The padding to use for the GID.

  • locale (String) (defaults to: "en")

    The locale to use for localized attributes.

Returns:

  • (String)


28
29
30
# File 'lib/product_taxonomy/models/serializers/attribute/dist/txt_serializer.rb', line 28

def serialize(attribute, padding: 0, locale: "en")
  "#{attribute.gid.ljust(padding)} : #{attribute.name(locale:)}"
end

.serialize_all(version:, locale: "en", padding: longest_gid_length) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/product_taxonomy/models/serializers/attribute/dist/txt_serializer.rb', line 9

def serialize_all(version:, locale: "en", padding: longest_gid_length)
  header = <<~HEADER
    # Shopify Product Taxonomy - Attributes: #{version}
    # Format: {GID} : {Attribute name}

  HEADER

  attributes_txt = ProductTaxonomy::Attribute
    .sorted_base_attributes
    .map { serialize(_1, padding:, locale:) }
    .join("\n")

  header + attributes_txt
end