phonetics 3.0.5 → 3.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94481afa417879a8512b0527cfa7b120dde840a5d0df59800591160a8651f43c
4
- data.tar.gz: e0ffd0cacb7ca1a79d88d7509c8a98dd10b86ef33c45991c31dde37f8b909d45
3
+ metadata.gz: fc5a5d7ba152639d347414b6639eb8298db4708217e61d3c4f4d7d240d45953f
4
+ data.tar.gz: e0d1d6625c34bf97aba3331340d924334555032cf776af467be94878d3b66e9b
5
5
  SHA512:
6
- metadata.gz: eb8566f0c4043fab8bd4d9183ccb0b9aa20a8a4fcd3dfbf0de250584dd69ce057382cd3cc1e2584ee48c83422cc8cabc56cb4a35a8b0a8f7330ae620f67eb9c1
7
- data.tar.gz: 244c9dd1d10c343ed3051d2f2d039af9e39ade146f4b48cf6f05e666f95e856ec2956170cfeaf6bb05fef54fd79852866e3d5300a9049e6073babc18261e08ca
6
+ metadata.gz: 7b88d3ebedb705b401908f4173db614ea3c869a88401542ef0e5f91c7a6973d80bb0f400708244eeed8c81028c5156a08990947dfc1e6f1581c2fed47d5c45ea
7
+ data.tar.gz: 9365e7ae84117bd0a470711279976019326f92de670a3990255aa8bd183568c50874aa7d5c52683e481abc6467b7dc7d8f07886e3ac6149ec08a18669fb22e10
data/.gitignore CHANGED
@@ -14,3 +14,4 @@
14
14
  *.so
15
15
  Gemfile.lock
16
16
  *.bundle
17
+ .ruby-version
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.5
1
+ 3.0.6
@@ -10,7 +10,8 @@ module Phonetics
10
10
 
11
11
  module Transcriptions
12
12
  extend self
13
- Transcriptions = File.join(__dir__, '..', 'common_ipa_transcriptions.json')
13
+
14
+ TranscriptionFile = File.join(__dir__, '..', 'common_ipa_transcriptions.json')
14
15
  TranscriptionsURL = 'https://jackdanger.com/common_ipa_transcriptions.json'
15
16
 
16
17
  SourcesByPreference = [/wiktionary/, /cmu/, /phonemicchart.com/].freeze
@@ -30,21 +31,21 @@ module Phonetics
30
31
 
31
32
  def transcriptions
32
33
  @transcriptions ||= begin
33
- download! unless File.exist?(Transcriptions)
34
+ download! unless File.exist?(TranscriptionFile)
34
35
  load_from_disk!
35
36
  end
36
37
  end
37
38
 
38
39
  # Lazily loaded from JSON file on disk
39
40
  def load_from_disk!
40
- @transcriptions = JSON.parse(File.read(Transcriptions))
41
+ @transcriptions = JSON.parse(File.read(TranscriptionFile))
41
42
  end
42
43
 
43
44
  def download!
44
45
  File.open(Transcriptions, 'w') { |f| f.write(URI.open(TranscriptionsURL).read) }
45
46
  end
46
47
 
47
- def trie
48
+ def trie(max_rarity = nil)
48
49
  # Let's turn this:
49
50
  #
50
51
  # "century": {
@@ -109,9 +110,14 @@ module Phonetics
109
110
  # },
110
111
  # },
111
112
  #
112
- @trie ||= begin
113
+ @tries ||= {}
114
+ @tries[max_rarity] ||= begin
113
115
  base_trie = {}
114
116
  transcriptions.each do |key, entry|
117
+ if max_rarity
118
+ next if entry['rarity'].nil? || entry['rarity'] > max_rarity
119
+ end
120
+
115
121
  entry_data = {
116
122
  word: key,
117
123
  rarity: entry['rarity'],
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phonetics
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.5
4
+ version: 3.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Danger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-27 00:00:00.000000000 Z
11
+ date: 2019-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler