Sha256: 03518cec7c23d6eae7020ab6ef929b3cd05e16bba697573fc2f87e8afebbfb66
Contents?: true
Size: 1.05 KB
Versions: 2
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true require "securerandom" require "pathname" module Haikunate require "haikunate/version" class << self attr_accessor :default_range attr_accessor :default_variant end self.default_range = 1000..9999 self.default_variant = -> { rand(default_range) } def self.data_dir @data_dir ||= Pathname.new(File.expand_path("#{__dir__}/../data")) end def self.nouns @nouns ||= data_dir.join("nouns.txt").read.lines.map(&:chomp) end def self.nouns=(nouns) @nouns = nouns.map(&:chomp) end def self.adjectives @adjectives ||= data_dir.join("adjectives.txt").read.lines.map(&:chomp) end def self.adjectives=(adjectives) @adjectives = adjectives.map(&:chomp) end def self.call(joiner: "-", variant: default_variant) [adjectives.sample, nouns.sample, variant.call].join(joiner) end def self.next(joiner: "-", variant: default_variant, &block) options = {joiner: joiner, variant: variant} name = call(**options) while !name || block.call(name) name end end Haiku = Haikunate
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
haikunate-0.1.1 | lib/haikunate.rb |
haikunate-0.1.0 | lib/haikunate.rb |