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.4.2 app/models/spree/address/name.rb
solidus_core-4.4.1 app/models/spree/address/name.rb
solidus_core-4.4.0 app/models/spree/address/name.rb
solidus_core-4.3.4 app/models/spree/address/name.rb
solidus_core-4.2.4 app/models/spree/address/name.rb
solidus_core-4.1.5 app/models/spree/address/name.rb
solidus_core-4.3.3 app/models/spree/address/name.rb
solidus_core-4.3.2 app/models/spree/address/name.rb
solidus_core-4.1.4 app/models/spree/address/name.rb
solidus_core-4.3.1 app/models/spree/address/name.rb
solidus_core-4.3.0 app/models/spree/address/name.rb
solidus_core-4.2.3 app/models/spree/address/name.rb
solidus_core-4.1.3 app/models/spree/address/name.rb
solidus_core-4.0.4 app/models/spree/address/name.rb
solidus_core-3.4.6 app/models/spree/address/name.rb
solidus_core-4.0.3 app/models/spree/address/name.rb
solidus_core-4.1.2 app/models/spree/address/name.rb
solidus_core-4.2.2 app/models/spree/address/name.rb
solidus_core-3.4.5 app/models/spree/address/name.rb
solidus_core-4.2.1 app/models/spree/address/name.rb