class Tansaku::Path

Public Class Methods

get_by_type(type) click to toggle source
# File lib/tansaku/path.rb, line 5
def self.get_by_type(type)
  new.get_by_type(type)
end

Public Instance Methods

get_by_type(type) click to toggle source
# File lib/tansaku/path.rb, line 9
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 Instance Methods

all() click to toggle source
# File lib/tansaku/path.rb, line 19
def all
  types.map { |type| get_by_type(type) }.flatten
end
types() click to toggle source
# File lib/tansaku/path.rb, line 23
def types
  @types = Dir.glob(File.expand_path("./lists/*.txt", __dir__)).map do |path|
    File.basename(path).split(".").first
  end
end
valid_type?(type) click to toggle source
# File lib/tansaku/path.rb, line 29
def valid_type?(type)
  return true if type == "all"

  types.include? type
end