Sha256: d543824e66e1498fa16b09d71bd8cbb9792b5d327652b13ed8bd66a9cf58c857

Contents?: true

Size: 733 Bytes

Versions: 1

Compression:

Stored size: 733 Bytes

Contents

require "yaml"

module PlatinaWorld
  class FileLoader
    DEFAULT_FILE_PATH = "./platina_world.yml".freeze
    ACCEPT_EXT_NAMES = %w(.yml .yaml).freeze

    def initialize(file_path = DEFAULT_FILE_PATH)
      @file_path = file_path
    end

    def load
      case
      when !exist_file?
        raise "#{file_path} is not found."
      when !valid_ext_name?
        raise "Ext name is invalid. plase pass .yml or .yaml file"
      else
        file_load
      end
    end

    private

    attr_reader :file_path

    def file_load
      YAML.load_file(file_path)
    end

    def exist_file?
      File.exist?(file_path)
    end

    def valid_ext_name?
      ACCEPT_EXT_NAMES.include?(File.extname(file_path))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
platina_world-0.1.0 lib/platina_world/file_loader.rb