Sha256: 581e6ba67b76fe30532584a0e2aaf25298ad2149398e7d5789b3c1e18eddec6f

Contents?: true

Size: 661 Bytes

Versions: 3

Compression:

Stored size: 661 Bytes

Contents

module Daigaku
  module Loadable
    def load(path)
      return [] unless Dir.exist?(path)

      dirs = Dir.entries(path).select do |entry|
        !entry.match(/\./)
      end

      dirs.sort.map do |dir|
        dir_path   = File.join(path, dir)
        module_name = demodulize(to_s)
        class_name = singularize(module_name)
        daigaku_class(class_name).new(dir_path)
      end
    end

    private

    def demodulize(string)
      string.split('::').last
    end

    def singularize(string)
      string.end_with?('s') ? string[0..-2] : string
    end

    def daigaku_class(name)
      Kernel.const_get("Daigaku::#{name}")
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
daigaku-1.0.0 lib/daigaku/loadable.rb
daigaku-0.6.0 lib/daigaku/loadable.rb
daigaku-0.5.0 lib/daigaku/loadable.rb