Sha256: 4b223536e2e8e41619a9834837daaac2f561db7521e7d6404113d28485681872

Contents?: true

Size: 674 Bytes

Versions: 1

Compression:

Stored size: 674 Bytes

Contents

module EmailAttribute
  class SingleAddress < String
    def initialize(str = "")
      @address = Mail::Address.new(str.to_s) rescue nil
      if @address
        value = @address.format
      else
        value = str || ""
      end
      super(value)
    end

    # rebuilds the Mail::Address if necessary
    # using string methods on this object can bypass the initializer
    def address
      @address ||= Mail::Address.new(self.to_s) rescue nil
    end

    class << self
      def dump(email_address)
        return nil if email_address.nil?

        email_address.to_s
      end

      def load(email_address)
        new(email_address)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
email_attribute-0.0.1 lib/email_attribute/single_address.rb