File: address_converter.rb

package info (click to toggle)
ruby-email-spec 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 980 kB
  • sloc: ruby: 2,420; makefile: 3
file content (29 lines) | stat: -rw-r--r-- 607 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'singleton'

module EmailSpec
  class AddressConverter
    include Singleton
  
    attr_accessor :converter
  
    # The block provided to conversion should convert to an email
    # address string or return the input untouched. For example:
    #
    #  EmailSpec::AddressConverter.instance.conversion do |input|
    #   if input.is_a?(User)
    #     input.email
    #   else
    #     input
    #   end
    #  end
    #    
    def conversion(&block)
      self.converter = block
    end
  
    def convert(input)
      return input unless converter
      converter.call(input)
    end
  end
end