wordmonger 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 67912799c0fb8adb04ca9a91d049c600adcc1918062b27305add71923f3acac9
4
+ data.tar.gz: 47bda97e3bf2261726c0400f4c171140936ec3275244aee47fbd1cb1914761f6
5
+ SHA512:
6
+ metadata.gz: 571b6ae975eedc08f8f9e6374810d5f9b20b94ae7f06570b16d590e9f1eb6d19358a0562de958627294a7d60a0edc4f61eb45702d616ac1a8401be6958c41e3f
7
+ data.tar.gz: c480c4c7f0c45be27a1c2f69f87aa30596e81e4a64de800b5412005f8352c273e6f6d6304e79dd1d5ceaa38e3e6edc1299f02adfb710094990579559707665c9
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Style/StringLiterals:
5
+ EnforcedStyle: double_quotes
6
+
7
+ Style/StringLiteralsInInterpolation:
8
+ EnforcedStyle: double_quotes
data/1 ADDED
@@ -0,0 +1,2 @@
1
+ direnv: unloading
2
+ direnv: unloading
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-04-22
4
+
5
+ - Initial release
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at richard.leber@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT LICENSE
2
+
3
+ Copyright (c) 2020 Richard LeBer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # wordmonger
2
+
3
+ This is a collection of tools to work with LEGO colors.
4
+
5
+ ## Installation
6
+
7
+ ### From Git
8
+
9
+ If installing for the system in general:
10
+
11
+ ```bash
12
+ git clone \<git repository url\> wordmonger
13
+ cd wordmonger
14
+ gem build wordmonger.gemspec
15
+ gem install wordmonger-\<version\>.gem # e.g. gem install wordmonger-1.0.0.gem
16
+
17
+ ```
18
+
19
+ If installing for a specific application, built with bundler, then replace the last command above with:
20
+
21
+ ```bash
22
+ cd \<your application root\>
23
+ bundle add wordmonger
24
+ bundle build
25
+ ```
26
+
27
+ ### From RubyGems
28
+
29
+ This gem has not been released to RubyGems. Maybe I will do that when I feel it's mature enough.
30
+
31
+ <!--
32
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem phrase right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
33
+
34
+ Install the gem and add to the application's Gemfile by executing:
35
+
36
+ ```bash
37
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
38
+ ```
39
+
40
+ If bundler is not being used to manage dependencies, install the gem by executing:
41
+
42
+ ```bash
43
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
44
+ ```
45
+ -->
46
+
47
+ ## Usage
48
+
49
+ ```wordmonger <command> <options>```
50
+
51
+ Type ```wordmonger help``` for a list of commands, or ```wordmonger help <command>``` for help with a specific command.
52
+
53
+ ## Development
54
+
55
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
56
+
57
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
58
+
59
+ ## Contributing
60
+
61
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rleber/model. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/rleber/model/blob/master/CODE_OF_CONDUCT.md).
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
66
+
67
+ ## Code of Conduct
68
+
69
+ Everyone interacting in the Model project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rleber/model/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/data/.gitkeep ADDED
File without changes
@@ -0,0 +1,60 @@
1
+ module WordMonger
2
+ class Dictionary
3
+ attr_reader :name, :phrases, :words
4
+ attr_accessor :abbreviations
5
+ def initialize(name, abbreviations: {}, scanner: nil)
6
+ @name = name
7
+ self.scanner = scanner
8
+ @phrases = {}
9
+ @words = {}
10
+ @abbreviations = abbreviations
11
+ WordMonger.add_dictionary(self)
12
+ end
13
+
14
+ def scanner
15
+ unless @scanner
16
+ self.scanner = WordMonger.default_scanner
17
+ end
18
+ @scanner
19
+ end
20
+
21
+ def scanner=(scanner)
22
+ @scanner = scanner.dup
23
+ @scanner.dictionary = self if @scanner
24
+ end
25
+
26
+ def activate
27
+ WordMonger.activate(self)
28
+ end
29
+
30
+ def add(phrase)
31
+ @phrases[phrase.text] = phrase
32
+ end
33
+
34
+ def delete(phrase)
35
+ text = phrase.is_a?(WordMonger::Phrase) ? phrase.text : phrase
36
+ @phrases.delete(text)
37
+ end
38
+
39
+ def serialize
40
+ @phrases.values.map { |value| value.serialize }
41
+ end
42
+
43
+ def add_abbreviation(abbreviation, abbreviates)
44
+ @abbreviations[abbreviation] = abbreviates
45
+ end
46
+
47
+ def delete_abbreviation(abbreviation)
48
+ @abbreviations.delete(abbreviation)
49
+ end
50
+
51
+ def add_word(word)
52
+ @words[word.text] = word
53
+ end
54
+
55
+ def delete_word(word)
56
+ text = word.is_a?(WordMonger::Word) ? word.text : word
57
+ @words.delete(text)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,74 @@
1
+ module WordMonger
2
+ class Phrase
3
+
4
+ attr_reader :text, :dictionary
5
+ def initialize(text, dictionary: nil)
6
+ self.text = text
7
+ @dictionary = dictionary || WordMonger.active_dictionary
8
+ @dictionary.add(self)
9
+ end
10
+
11
+ def to_s
12
+ @text
13
+ end
14
+
15
+ def serialize
16
+ to_s
17
+ end
18
+
19
+ def scanner
20
+ @dictionary.scanner
21
+ end
22
+
23
+ def text=(text)
24
+ @text = text
25
+ @words = nil
26
+ @expanded = nil
27
+ end
28
+
29
+ # TODO Make words first-class objects?
30
+ private def get_words
31
+ return [] unless @text
32
+ self.scanner.scan(@text)
33
+ end
34
+
35
+ def words
36
+ @words ||= get_words
37
+ end
38
+
39
+ private def case_preserving_sub(text, from, to)
40
+ match_regexp = Regexp.new(Regexp.escape(from), Regexp::IGNORECASE)
41
+ from_text = text[match_regexp]
42
+ to_text = to.downcase
43
+ first_from_char = from_text[0]
44
+ if first_from_char == first_from_char.upcase
45
+ to_text = (to_text[0].upcase) + to_text[1..]
46
+ end
47
+ text.sub(from_text, to_text)
48
+ end
49
+
50
+ private def get_expanded
51
+ expanded_name = self.text
52
+ self.words.each do |word|
53
+ lowercase_word = word.text.downcase
54
+ substitute = dictionary.abbreviations[lowercase_word]
55
+ if substitute
56
+ expanded_name = case_preserving_sub(expanded_name, word.text, substitute)
57
+ end
58
+ end
59
+ expanded_name
60
+ end
61
+
62
+ def expanded
63
+ @expanded ||= self.class.new(get_expanded)
64
+ end
65
+
66
+ def expanded_name
67
+ expanded.phrase
68
+ end
69
+
70
+ def expanded_words
71
+ self.expanded.words
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,47 @@
1
+ module WordMonger
2
+ class Scanner
3
+ @@scanners = {}
4
+
5
+ class ScannerFailure < WordMonger::Error; end
6
+
7
+ class << self
8
+ def scanners
9
+ @@scanners
10
+ end
11
+
12
+ def add_scanner(name, scanner)
13
+ @@scanners[name] = scanner
14
+ end
15
+
16
+ def default
17
+ @@default ||= self.new(nil, /\w+/)
18
+ @@default
19
+ end
20
+ end
21
+
22
+ attr_reader :name, :definition
23
+ attr_accessor :dictionary
24
+ def initialize(name, definition, dictionary: nil)
25
+ @name = name
26
+ @definition = definition
27
+ @dictionary ||= WordMonger.active_dictionary
28
+ self.class.add_scanner(name, self)
29
+ end
30
+
31
+ # TODO For future development: Compound words
32
+
33
+ def scan(string)
34
+ words = case @definition
35
+ when Regexp
36
+ string.scan(@definition)
37
+ when Proc
38
+ Proc.call(string)
39
+ when nil
40
+ single_scan(string, self.class.default)
41
+ else
42
+ raise ScannerFailure, "Unknow scanner type: #{scanner.inspect}"
43
+ end
44
+ words.map { |word| WordMonger::Word.new(word, dictionary: self.dictionary) }
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WordMonger
4
+ VERSION = "0.0.1"
5
+ end
@@ -0,0 +1,70 @@
1
+ module WordMonger
2
+ class Word
3
+
4
+ attr_reader :text, :dictionary
5
+ def initialize(text, dictionary: nil)
6
+ self.text = text
7
+ @dictionary = dictionary || WordMonger.active_dictionary
8
+ @dictionary.add_word(self)
9
+ end
10
+
11
+ def serialize
12
+ @text
13
+ end
14
+
15
+ def scanner
16
+ @dictionary.scanner
17
+ end
18
+
19
+ def text=(text)
20
+ @text = text
21
+ @words = nil
22
+ @expanded = nil
23
+ end
24
+
25
+ # TODO Make words first-class objects?
26
+ private def get_words
27
+ return [] unless @text
28
+ @scanner.scan(@text)
29
+ end
30
+
31
+ def words
32
+ @words ||= get_words
33
+ end
34
+
35
+ private def case_preserving_sub(text, from, to)
36
+ match_regexp = Regexp.new(Regexp.escape(from), Regexp::IGNORECASE)
37
+ from_text = text[match_regexp]
38
+ to_text = to.downcase
39
+ first_from_char = from_text[0]
40
+ if first_from_char == first_from_char.upcase
41
+ to_text = (to_text[0].upcase) + to_text[1..]
42
+ end
43
+ text.sub(from_text, to_text)
44
+ end
45
+
46
+ private def get_expanded
47
+ expanded_name = self.text
48
+ self.words.each do |word|
49
+ lowercase_word = word.downcase
50
+ substitute = dictionary.abbreviations[lowercase_word]
51
+ if substitute
52
+ expanded_name = case_preserving_sub(expanded_name, word, substitute)
53
+ end
54
+ end
55
+ expanded_name
56
+ end
57
+
58
+ def expanded
59
+ @expanded ||= self.class.new(get_expanded)
60
+ end
61
+
62
+ def expanded_name
63
+ expanded.phrase
64
+ end
65
+
66
+ def expanded_words
67
+ self.expanded.words
68
+ end
69
+ end
70
+ end
data/lib/wordmonger.rb ADDED
@@ -0,0 +1,62 @@
1
+ module WordMonger
2
+
3
+ class Error < StandardError; end
4
+ class DuplicateDictionary < Error; end
5
+ class UndefinedDictionary < Error; end
6
+
7
+ class << self
8
+ def dictionaries
9
+ @@dictionaries ||= {}
10
+ end
11
+
12
+ def dictionary(name=nil)
13
+ self.dictionaries[name]
14
+ end
15
+
16
+ def add_dictionary(dictionary)
17
+ raise Error, "Can't add a nil dictionary" unless dictionary
18
+ name = dictionary.name
19
+ raise DuplicateDictionary if self.dictionary(name)
20
+ @@dictionaries[name] = dictionary
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ require_relative 'wordmonger/version'
27
+ require_relative 'wordmonger/phrase'
28
+ require_relative 'wordmonger/word'
29
+ require_relative 'wordmonger/dictionary'
30
+ require_relative 'wordmonger/scanner'
31
+
32
+ module WordMonger
33
+
34
+ DEFAULT_VENDOR = :lego
35
+
36
+ @@active_dictionary = WordMonger::Dictionary.new(nil)
37
+
38
+ class << self
39
+
40
+ def default_scanner
41
+ @@default_scanner
42
+ end
43
+
44
+ def active_dictionary
45
+ @@active_dictionary
46
+ end
47
+
48
+ def active_scanner
49
+ @@active_dictionary.scanner
50
+ end
51
+
52
+ def default_scanner
53
+ @@default_scanner ||= WordMonger::Scanner.default
54
+ end
55
+
56
+ def activate(name=nil)
57
+ dictionary = dictionary(name)
58
+ raise UndefinedDictionary unless dictionary
59
+ @@active_dictionary = dictionary
60
+ end
61
+ end
62
+ end
data/output/.gitkeep ADDED
File without changes
@@ -0,0 +1,4 @@
1
+ module WordMonger
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wordmonger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Richard LeBer
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ email:
13
+ - richard.leber@gmail.com
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - ".rspec"
19
+ - ".rubocop.yml"
20
+ - '1'
21
+ - CHANGELOG.md
22
+ - CODE_OF_CONDUCT.md
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - data/.gitkeep
27
+ - lib/wordmonger.rb
28
+ - lib/wordmonger/dictionary.rb
29
+ - lib/wordmonger/phrase.rb
30
+ - lib/wordmonger/scanner.rb
31
+ - lib/wordmonger/version.rb
32
+ - lib/wordmonger/word.rb
33
+ - output/.gitkeep
34
+ - sig/wordmonger.rbs
35
+ homepage: https://github.com/rleber/wordmonger
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ homepage_uri: https://github.com/rleber/wordmonger
40
+ changelog_uri: https://github.com/rleber/wordmonger/blob/master/CHANGELOG.md
41
+ rdoc_options: []
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 3.1.0
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubygems_version: 3.6.9
56
+ specification_version: 4
57
+ summary: Work with words, synonyms, and abbreviations
58
+ test_files: []