Sha256: c8fc8d66e3dcd3e7b5176e3bdd08dfcc2b6e0d1d6f9abbd75f6a19219354a99b
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
require_relative '../lib/story_key' def noun_entries { countable: [], uncountable: [] }.tap do |data| Dir.glob('lexicons/nouns/**/*.txt') do |path| group = path.split('/')[-2] == 'countable' ? :countable : :uncountable data[group] += txtfile_lines(path) end data.each { |group, entries| data[group] = entries.sort } end end def verb_entries { entries: txtfile_lines('lexicons/verbs/entries.txt') } end def adjective_entries entries = [] Dir.glob('lexicons/adjectives/*.txt') do |path| entries += txtfile_lines(path) end { entries: entries.sort } end def txtfile_lines(path) File.readlines(path) .map(&:strip) .reject { |l| l.start_with?('#') || l.blank? } end namespace :lexicon do desc 'Build lib/story_key/data.rb from text files' task :build do output_file = 'lib/story_key/data.rb' str = <<~TEXT # This was auto-generated by `rake lexicon:build` at #{Time.current} # from text files stored in /lexicons module StoryKey::Data ENTRIES = { TEXT str += [].tap do |ary| StoryKey::GRAMMAR.values.flatten.uniq.each do |part_of_speech| substr = " #{part_of_speech}: {\n" substr += [].tap do |ary2| send("#{part_of_speech}_entries").each do |group, entries| elements = entries.map { |e| "'#{e}'" }.join(', ') ary2 << " #{group}: [#{elements}]" end end.join(",\n") ary << "#{substr}\n }" end end.join(",\n") str += <<~TEXT }.freeze end TEXT File.write(output_file, str) puts "#{output_file} written" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
story_key-0.5.0 | rakelib/lexicon.rake |