Class: Meteor::Core::Util::FileReader

Inherits:
Object
  • Object
show all
Defined in:
lib/meteor/core/util/file_reader.rb

Overview

FileReader Class (ファイル・リーダー クラス)

Class Method Summary collapse

Class Method Details

.read(file_path, enc) ⇒ Object

read file (ファイルを読み込む)

Parameters:

  • file_path (String)

    absolute path of input file (入力ファイルの絶対パス)

  • enc (String)

    character encoding of input file (入力ファイルの文字コード)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/meteor/core/util/file_reader.rb', line 15

def self.read(file_path, enc)
  mode = if enc == 'UTF-8'
           # String.new("") << "r:" << enc
           'r:UTF-8'
         else
           String.new('') << 'r:' << enc << ':utf-8'
         end

  # open file (ファイルのオープン)
  io = File.open(file_path, mode)

  # load (読込)
  data = io.read

  # close file (ファイルのクローズ)
  io.close

  data
end