Sha256: 60d9b3ffaa41bbcf9b25cef870e7b24ba857c6fde62f5588df01ac87924010ce

Contents?: true

Size: 728 Bytes

Versions: 1

Compression:

Stored size: 728 Bytes

Contents

# frozen_string_literal: true

module SocialUrl
  class Message
    def initialize(options)
      @options = SocialUrl.normalize(options)

      init_networks
    end

    def method_missing(method)
      network = /(.+)_url/.match(method)
      return unless network

      networks = SocialUrl.networks.join(",")
      raise UnsupportedNetworkError,
           "Unsupported network '#{network[1]}'. Choose from: #{networks}."
    end

    private
      def init_networks
        SocialUrl.networks.each do |network|
          self.class.send(:define_method, "#{network}_url") do
            klass = network.to_s.capitalize
            SocialUrl.const_get(klass).new(@options).url
          end
        end
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
social-url-1.1.1 lib/social_url/message.rb