Sha256: 8c451cbbab9b7f00df80f278497c0e4a38d96d4a8db61472753c35fe67beb982

Contents?: true

Size: 682 Bytes

Versions: 67

Compression:

Stored size: 682 Bytes

Contents

# frozen_string_literal: true

module Spree
  class Address
    # Provides a value object to help splitting and joining
    # name fields
    class Name
      attr_reader :first_name, :last_name, :value

      def initialize(*components)
        @value = components.join(' ').strip
        initialize_name_components(components)
      end

      def to_s
        @value
      end

      private

      def initialize_name_components(components)
        if components.size == 2
          @first_name = components[0].to_s
          @last_name = components[1].to_s
        else
          @first_name, @last_name = @value.split(/[[:space:]]/, 2)
        end
      end
    end
  end
end

Version data entries

67 entries across 67 versions & 1 rubygems

Version Path
solidus_core-4.2.0 app/models/spree/address/name.rb
solidus_core-4.1.1 app/models/spree/address/name.rb
solidus_core-4.0.2 app/models/spree/address/name.rb
solidus_core-3.4.4 app/models/spree/address/name.rb
solidus_core-3.3.4 app/models/spree/address/name.rb
solidus_core-3.2.9 app/models/spree/address/name.rb
solidus_core-3.2.8 app/models/spree/address/name.rb
solidus_core-3.3.3 app/models/spree/address/name.rb
solidus_core-3.4.3 app/models/spree/address/name.rb
solidus_core-4.0.1 app/models/spree/address/name.rb
solidus_core-4.1.0 app/models/spree/address/name.rb
solidus_core-4.0.0 app/models/spree/address/name.rb
solidus_core-3.4.2 app/models/spree/address/name.rb
solidus_core-3.2.7 app/models/spree/address/name.rb
solidus_core-3.3.2 app/models/spree/address/name.rb
solidus_core-3.4.1 app/models/spree/address/name.rb
solidus_core-3.4.0 app/models/spree/address/name.rb
solidus_core-3.3.1 app/models/spree/address/name.rb
solidus_core-3.2.6 app/models/spree/address/name.rb
solidus_core-3.1.9 app/models/spree/address/name.rb