Sha256: 6f7a9b6df7efe386ad1b2e15385f04cfe2528481002bfa8ee2e2fffb998a18b7

Contents?: true

Size: 945 Bytes

Versions: 16

Compression:

Stored size: 945 Bytes

Contents

# frozen_string_literal: true

require 'eac_ruby_utils/core_ext'
require 'ehbrs_ruby_utils/executables'

module EhbrsRubyUtils
  module Mudslide
    class Message
      acts_as_immutable
      immutable_accessor :image_path, :recipient, :text

      def deliver
        raise 'No recipient set' if recipient.blank?

        if image_path.present?
          deliver_image
        elsif text.present?
          deliver_text
        else
          deliver
        end
      end

      private

      # @return [void]
      def deliver_image
        args = ['send-image']
        text.if_present { |_v| args += ['--caption', text] }
        mudslide_run(*args, recipient, image_path)
      end

      # @return [void]
      def deliver_text
        mudslide_run('send', recipient, text)
      end

      # @return [void]
      def mudslide_run(*args)
        ::EhbrsRubyUtils::Executables.mudslide.command(*args).system!
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ehbrs_ruby_utils-0.44.1 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.44.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.41.1 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.41.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.40.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.39.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.38.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.37.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.36.1 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.36.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.35.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.33.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.32.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.31.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.30.0 lib/ehbrs_ruby_utils/mudslide/message.rb
ehbrs_ruby_utils-0.29.0 lib/ehbrs_ruby_utils/mudslide/message.rb