#
#= 出力処理機能群
# Authors:: Sumiyo Yamamoto
# Copyright:: Copyright (C) OrbusNeich Medical K.K.  2010.
#--
# date        name                   note
# 2010.3.5    Sumiyo Yamamoto        新規作成
#-------------------------------------------------------------------------------
#++
module Comm
  module Module
    #= 出力処理機能モジュール
    # 出力処理に使えるメソッド群を備える。
    #------------------------------------------------------------------------#++
    module Print
      include Comm::Const::Print

    protected
      #== 出力ファイル送信実行
      #_pdata_ :: 出力ファイルデータ
      #_ftype_ :: ファイルタイプ
      #_fname_ :: ファイル名
      #
      # 戻り値:: ファイル名
      #-----------------------------------------------------------------#++
      def send_pdata(pdata = nil, ftype = nil, fname = nil)
        # ファイルタイプ情報取得
        idx = FILE_TYPE_INFO.search_val(ftype, :type)
        finfo = FILE_TYPE_INFO[idx]
        
        # ファイル名取得
        all_fname = get_file_name(fname, finfo[:ext])
        
        # 送信実行
        send_data(
          pdata,
          :filename => all_fname,
          :content_type  => finfo[:ctype]
        )
      end

      #== ファイル名生成
      #_fname_ :: ファイル名先頭文字列
      #_ext_ :: 拡張子
      #
      # 戻り値:: ファイル名
      #-----------------------------------------------------------------#++
      def get_file_name(fname = nil, ext = nil)
        if fname.blank?
          fname = 'file-'
        else
          fname += '-'
        end
        return fname + Time.now.strftime("%y%m%d-%H%M") + '.' + ext
      end
    end
  end
end
