gamefic-grammar 1.0.0

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: 10008329b01a95915decf94ff527edfc8517ff482c65ae88acda2dd742d7f87a
4
+ data.tar.gz: 3ba359d9beea9c2ae52f2ddfc82688e5867c784cff3d08eee7a8aee09303e47c
5
+ SHA512:
6
+ metadata.gz: c294e15930f57094f6225b76bfaba7eda92eb277c4e4a0aebb82064a79b0b53ba0f620c82d91f0f17dcc6a0c7d272b8aa2e4dd566ed6a3d03a7f5843b41071a8
7
+ data.tar.gz: 51d6b790ff732baba0271624cace49fba93c4144798d39a6689fdf8c2ff9adb9b61549695e5c6f5e2399ef7525bde0d7e2d10e7a2e4a0ac8184bc9f9cdee738e
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,2 @@
1
+ ## 1.0.0 - September 30, 2024
2
+ - First release
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Fred Snyder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # Gamefic::Grammar
2
+
3
+ English grammar rules for Gamefic entities.
4
+
5
+ ## Installation
6
+
7
+ **If your project uses gamefic-standard, gamefic-grammar is already included.**
8
+
9
+ Add the library to your Gamefic project's Gemfile:
10
+
11
+ ```
12
+ gem 'gamefic-grammar'
13
+ ```
14
+
15
+ Run `bundle install`.
16
+
17
+ Add the requirement to your project's code (typically in `main.rb`):
18
+
19
+ ```
20
+ require 'gamefic-grammar'
21
+
22
+ ## Usage
23
+
24
+ An entity's `gender` attribute can be `:male`, `:female`, `:neutral`, or `:other`. Default is `:neutral`.
25
+
26
+ ```ruby
27
+ woman = Gamefic::Entity.new(name: 'woman', gender: :female)
28
+ woman.subjective #=> "she"
29
+ woman.objective #=> "her"
30
+ woman.possessive #=> "her"
31
+ woman.reflexive #=> "herself"
32
+ ```
33
+
34
+ An entity's `plural?` attribute is boolean. Default is false.
35
+
36
+ ```ruby
37
+ shoes = Gamefic::Entity.new(name: 'shoes', plural: true)
38
+ shoes.plural? #=> true
39
+ "The #{shoes.name} #{shoes.maybe_plural('is', 'are')} red." #=> "The shoes are red."
40
+ ```
41
+
42
+ ## Development
43
+
44
+ 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.
45
+
46
+ 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).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/castwide/gamefic-grammar.
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'opal/rspec/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
10
+
11
+ Opal::RSpec::RakeTask.new(:opal) do |_, config|
12
+ Opal.append_path File.join(__dir__, 'lib')
13
+ Opal.use_gem 'gamefic'
14
+ config.default_path = 'spec'
15
+ config.pattern = 'spec/**/*_spec.rb'
16
+ config.requires = ['opal_helper']
17
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/gamefic/grammar/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'gamefic-grammar'
7
+ spec.version = Gamefic::Grammar::VERSION
8
+ spec.authors = ['Fred Snyder']
9
+ spec.email = ['fsnyder@castwide.com']
10
+
11
+ spec.summary = 'English grammar rules for Gamefic entities.'
12
+ # spec.description = "TODO: Write a longer description or delete this line."
13
+ spec.homepage = 'https://gamefic.com'
14
+ spec.required_ruby_version = '>= 2.6.0'
15
+
16
+ # spec.metadata['allowed_push_host'] = "TODO: Set to your gem server 'https://example.com'"
17
+
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/castwide/gamefic-grammar'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/castwide/gamefic-grammar/blob/master/CHANGELOG.md'
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(__dir__) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (File.expand_path(f) == __FILE__) ||
27
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
28
+ end
29
+ end
30
+ spec.bindir = 'exe'
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ['lib']
33
+
34
+ # Uncomment to register a new dependency of your gem
35
+ # spec.add_dependency "example-gem", "~> 1.0"
36
+ spec.add_dependency 'gamefic', '~> 3.0'
37
+
38
+ spec.add_development_dependency 'opal-rspec', '~> 1.0'
39
+ spec.add_development_dependency 'opal-sprockets', '~> 1.0'
40
+ spec.add_development_dependency 'rake', '~> 13.0'
41
+ spec.add_development_dependency 'rspec', '~> 3.0'
42
+ spec.add_development_dependency 'simplecov', '~> 0.22'
43
+
44
+ # For more information and examples about making a new gem, check out our
45
+ # guide at: https://bundler.io/guides/creating_gem.html
46
+ end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gamefic
4
+ module Grammar
5
+ # A collection of attributes that enable grammar features for entities, such
6
+ # as selecting their correct pronouns.
7
+ #
8
+ module Attributes
9
+ # @see #gender
10
+ attr_writer :gender
11
+
12
+ # @see #plural?
13
+ attr_writer :plural
14
+
15
+ # The gender of the object. Supported values are :male, :female, :neutral,
16
+ # and :other. Use :neutral for objects that don't have a gender (i.e.,
17
+ # "it"). Use :other for people or characters that have an unspecified or
18
+ # non-binary gender (i.e., "they").
19
+ #
20
+ # @return [Symbol]
21
+ def gender
22
+ @gender ||= :neutral
23
+ end
24
+
25
+ # True if the object should be referred to in the plural, e.g., "they"
26
+ # instead of "it."
27
+ # @return [Boolean]
28
+ #
29
+ def plural?
30
+ @plural ||= false
31
+ end
32
+
33
+ # For now, the object's person is always assumed to be third
34
+ # (he/she/it/they). A future version of this library might support first
35
+ # (I/me) and second (you).
36
+ def person
37
+ 3
38
+ end
39
+
40
+ # @param singular_text [String]
41
+ # @param plural_text [String]
42
+ # @return [String]
43
+ def maybe_plural(singular_text, plural_text = "#{singular_text}s")
44
+ plural? ? plural_text : singular_text
45
+ end
46
+
47
+ def objective
48
+ Pronoun.objective self
49
+ end
50
+ alias him objective
51
+ alias them objective
52
+
53
+ def objective_
54
+ Pronoun.objective_ self
55
+ end
56
+ alias him_ objective_
57
+ alias them_ objective_
58
+ alias Him objective_
59
+ alias Them objective_
60
+
61
+ def subjective
62
+ Pronoun.subjective self
63
+ end
64
+ alias he subjective
65
+ alias she subjective
66
+ alias they subjective
67
+
68
+ def subjective_
69
+ Pronoun.subjective_ self
70
+ end
71
+ alias he_ subjective_
72
+ alias she_ subjective_
73
+ alias they_ subjective_
74
+ alias He subjective_
75
+ alias She subjective_
76
+ alias They subjective_
77
+
78
+ def possessive
79
+ Pronoun.possessive self
80
+ end
81
+ alias his possessive
82
+ alias their possessive
83
+ alias its possessive
84
+
85
+ def possessive_
86
+ Pronoun.possessive_ self
87
+ end
88
+ alias his_ possessive_
89
+ alias their_ possessive_
90
+ alias its_ possessive_
91
+ alias His possessive_
92
+ alias Their possessive_
93
+ alias Its possessive_
94
+
95
+ def reflexive
96
+ Pronoun.reflexive self
97
+ end
98
+ alias himself reflexive
99
+ alias herself reflexive
100
+ alias itself reflexive
101
+ alias themselves reflexive
102
+ alias themself reflexive
103
+
104
+ def reflexive_
105
+ Pronoun.reflexive_ self
106
+ end
107
+ alias himself_ reflexive_
108
+ alias herself_ reflexive_
109
+ alias itself_ reflexive_
110
+ alias themselves_ reflexive_
111
+ alias themself_ reflexive_
112
+ alias Himself reflexive_
113
+ alias Herself reflexive_
114
+ alias Itself reflexive_
115
+ alias Themselves reflexive_
116
+ alias Themself reflexive_
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gamefic
4
+ module Grammar
5
+ # Methods to select pronouns based on an entity's attributes, such as
6
+ # gender.
7
+ #
8
+ module Pronoun
9
+ module_function
10
+
11
+ MAP_KEYS = %i[subjective objective possessive reflexive].freeze
12
+
13
+ MAPS = {
14
+ [1, :singular] => Hash[MAP_KEYS.zip(%w[I me my myself])],
15
+ [2, :singular] => Hash[MAP_KEYS.zip(%w[you you your yourself])],
16
+ [3, :singular] => Hash[MAP_KEYS.zip(%w[it it its itself])],
17
+ [3, :singular, :male] => Hash[MAP_KEYS.zip(%w[he him his himself])],
18
+ [3, :singular, :female] => Hash[MAP_KEYS.zip(%w[she her her herself])],
19
+ [3, :singular, :other] => Hash[MAP_KEYS.zip(%w[they them their themselves])],
20
+ [3, :singular, :neutral] => Hash[MAP_KEYS.zip(%w[it it its itself])],
21
+ [1, :plural] => Hash[MAP_KEYS.zip(%w[we us our ourselves])],
22
+ [2, :plural] => Hash[MAP_KEYS.zip(%w[you you your yourselves])],
23
+ [3, :plural] => Hash[MAP_KEYS.zip(%w[they them their themselves])]
24
+ }.freeze
25
+
26
+ # @param entity [#person, #plural?, #gender]
27
+ # @return [String]
28
+ def subjective(entity)
29
+ prounoun_map(entity)[:subjective]
30
+ end
31
+ alias they subjective
32
+ alias he subjective
33
+ alias she subjective
34
+
35
+ # @param entity [#person, #plural?, #gender]
36
+ # @return [String]
37
+ def subjective_(entity)
38
+ subjective(entity).cap_first
39
+ end
40
+ alias they_ subjective_
41
+ alias he_ subjective_
42
+ alias she_ subjective_
43
+
44
+ # @param entity [#person, #plural?, #gender]
45
+ # @return [String]
46
+ def objective(entity)
47
+ prounoun_map(entity)[:objective]
48
+ end
49
+ alias them objective
50
+
51
+ # @param entity [#person, #plural?, #gender]
52
+ # @return [String]
53
+ def objective_(entity)
54
+ objective(entity).cap_first
55
+ end
56
+ alias them_ objective_
57
+
58
+ # @param entity [#person, #plural?, #gender]
59
+ # @return [String]
60
+ def possessive(entity)
61
+ prounoun_map(entity)[:possessive]
62
+ end
63
+ alias their possessive
64
+
65
+ # @param entity [#person, #plural?, #gender]
66
+ # @return [String]
67
+ def possessive_(entity)
68
+ possessive(entity).cap_first
69
+ end
70
+ alias their_ possessive_
71
+
72
+ # @param entity [#person, #plural?, #gender]
73
+ # @return [String]
74
+ def reflexive(entity)
75
+ prounoun_map(entity)[:reflexive]
76
+ end
77
+ alias themselves reflexive
78
+ alias themself reflexive
79
+
80
+ # @param entity [#person, #plural?, #gender]
81
+ # @return [String]
82
+ def reflexive_(entity)
83
+ reflexive(entity).cap_first
84
+ end
85
+ alias themselves_ reflexive_
86
+ alias themself_ reflexive_
87
+
88
+ # @param entity [#person, #plural?, #gender]
89
+ # @return [Hash]
90
+ def prounoun_map(entity)
91
+ plurality = (entity.plural? ? :plural : :singular)
92
+ MAPS[[entity.person || 3, plurality, entity.gender]] ||
93
+ MAPS[[entity.person || 3, plurality]]
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Gamefic
4
+ module Grammar
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gamefic'
4
+
5
+ module Gamefic
6
+ module Grammar
7
+ require 'gamefic/grammar/version'
8
+ require 'gamefic/grammar/attributes'
9
+ require 'gamefic/grammar/pronoun'
10
+ end
11
+ end
12
+
13
+ module Gamefic
14
+ class Entity
15
+ include Grammar::Attributes
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'gamefic/grammar'
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gamefic-grammar
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Fred Snyder
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-09-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gamefic
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: opal-rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: opal-sprockets
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.22'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.22'
97
+ description:
98
+ email:
99
+ - fsnyder@castwide.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".rspec"
105
+ - CHANGELOG.md
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - gamefic-grammar.gemspec
110
+ - lib/gamefic-grammar.rb
111
+ - lib/gamefic/grammar.rb
112
+ - lib/gamefic/grammar/attributes.rb
113
+ - lib/gamefic/grammar/pronoun.rb
114
+ - lib/gamefic/grammar/version.rb
115
+ homepage: https://gamefic.com
116
+ licenses: []
117
+ metadata:
118
+ homepage_uri: https://gamefic.com
119
+ source_code_uri: https://github.com/castwide/gamefic-grammar
120
+ changelog_uri: https://github.com/castwide/gamefic-grammar/blob/master/CHANGELOG.md
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: 2.6.0
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubygems_version: 3.3.7
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: English grammar rules for Gamefic entities.
140
+ test_files: []