Sha256: 7fe1ba00fb28e0b03f7891744044a316fea96d48f3f7eb437453060fa9da313d

Contents?: true

Size: 725 Bytes

Versions: 7

Compression:

Stored size: 725 Bytes

Contents

# frozen_string_literal: true

module Tansaku
  class Path
    def self.get_by_type(type)
      new.get_by_type(type)
    end

    def get_by_type(type)
      raise ArgumentError, "Invalid type is given. #{type} is not supported." unless valid_type?(type)

      return all if type == "all"

      File.readlines(File.expand_path("./lists/#{type}.txt", __dir__))
    end

    private

    def all
      types.map { |type| get_by_type(type) }.flatten
    end

    def types
      @types = Dir.glob(File.expand_path("./lists/*.txt", __dir__)).map do |path|
        File.basename(path).split(".").first
      end
    end

    def valid_type?(type)
      return true if type == "all"

      types.include? type
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
tansaku-1.4.0 lib/tansaku/path.rb
tansaku-1.3.0 lib/tansaku/path.rb
tansaku-1.1.0 lib/tansaku/path.rb
tansaku-1.0.0 lib/tansaku/path.rb
tansaku-0.3.0 lib/tansaku/path.rb
tansaku-0.2.1 lib/tansaku/path.rb
tansaku-0.2.0 lib/tansaku/path.rb