Sha256: 3e2d8e73e73e7f18f4bc1bc81c45606d531a731071174dd5e03ae82f2d05f785

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

class StoryKey::Lexicon < StoryKey::Base
  def entries
    @entries ||= StoryKey::GRAMMAR.values.flatten.uniq.index_with do |part_of_speech|
      import_entries(part_of_speech).sort_by(&:token)
    end
  end

  def prepositions
    @prepositions ||= entries.values.flatten.filter_map(&:preposition).uniq.sort
  end

  def sha
    @sha ||= Digest::SHA256.hexdigest(entries.to_s).first(StoryKey::LEXICON_SHA_SIZE)
  end

  private

  def import_entries(part_of_speech)
    [].tap do |ary|
      StoryKey::Data::ENTRIES[part_of_speech].each do |group, entries|
        entries.each do |text|
          ary << new_entry(part_of_speech, text, group == :countable)
        end
      end
    end
  end

  def new_entry(part_of_speech, text, countable)
    StoryKey::Entry.new \
      part_of_speech:,
      raw: text,
      text: text.gsub(/\[|\]/, ""),
      token: StoryKey::Tokenizer.call(text),
      countable:,
      preposition: text.match(/\[(.+)\]/).to_a[1]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
story_key-0.5.0 lib/story_key/lexicon.rb