Sha256: 52172e542c441703cc43ffeb2b3a2d5620c258c951c92270493a04e917fd303f
Contents?: true
Size: 773 Bytes
Versions: 2
Compression:
Stored size: 773 Bytes
Contents
# frozen_string_literal: true require_relative "../jp_local_gov" module JpLocalGov module Random DATA_DIR = "#{File.dirname(__FILE__)}/../../data/json/".freeze RANDOMIZE_TARGET = %w[code city city_kana prefecture prefecture_code prefecture_kana].freeze module_function RANDOMIZE_TARGET.each do |target| define_method target.to_s do sample_data.send(target) end end def sample_data file_name = ("1".."47").to_a.sample&.rjust(2, "0") json_file = "#{DATA_DIR}#{file_name}.json" data = JSON.parse(File.read(json_file), { symbolize_names: true }) JpLocalGov::LocalGov.new(data[data.keys.sample]) end private_class_method :sample_data private_constant :DATA_DIR, :RANDOMIZE_TARGET end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
jp_local_gov-0.2.1 | lib/jp_local_gov/random.rb |
jp_local_gov-0.2.0 | lib/jp_local_gov/random.rb |