to_stars 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ff6cb08b0e4d7fc3ef0f2e8bc976ba23ed34bf689f94260e2b9592a824a14a50
4
+ data.tar.gz: af6bb3239e1cc40920e399ae30153d61ae773abefdf16b69556491b7206abd4c
5
+ SHA512:
6
+ metadata.gz: 2b7b5a194e936e8e0ddfd91d25804c2ac03ae98792f3db97986359b4e36451de234d148651d59b9a077c6f1d18e287dd8e48cf1e1f2ba3b5b08edfaeba435776
7
+ data.tar.gz: aacdbcca26e4ec9c50d380bcb776c63f7efe631cfda62488cef47a098ae3441d321fd39c0d20adfe0b0704b858076d18833a059cf2d81efd85d41ea17e07ab49
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+
5
+ Style/StringLiterals:
6
+ Enabled: true
7
+ EnforcedStyle: single_quotes
8
+
9
+ Style/StringLiteralsInInterpolation:
10
+ Enabled: true
11
+ EnforcedStyle: double_quotes
12
+
13
+ Layout/LineLength:
14
+ Max: 120
15
+
16
+ Metrics/MethodLength:
17
+ Max: 30
18
+
19
+ Metrics/BlockLength:
20
+ Max: 30
21
+
22
+ Gemspec/RequireMFA:
23
+ Enabled: false
24
+
25
+ Lint/RedundantCopDisableDirective:
26
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2023-01-08
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at TODO: Write your email address. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in to_stars.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rspec', '~> 3.0'
11
+
12
+ gem 'rubocop', '~> 1.21'
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ to_stars (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ diff-lcs (1.5.0)
11
+ json (2.6.3)
12
+ parallel (1.22.1)
13
+ parser (3.2.0.0)
14
+ ast (~> 2.4.1)
15
+ rainbow (3.1.1)
16
+ rake (13.0.6)
17
+ regexp_parser (2.6.1)
18
+ rexml (3.2.5)
19
+ rspec (3.12.0)
20
+ rspec-core (~> 3.12.0)
21
+ rspec-expectations (~> 3.12.0)
22
+ rspec-mocks (~> 3.12.0)
23
+ rspec-core (3.12.0)
24
+ rspec-support (~> 3.12.0)
25
+ rspec-expectations (3.12.2)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.12.0)
28
+ rspec-mocks (3.12.2)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.12.0)
31
+ rspec-support (3.12.0)
32
+ rubocop (1.42.0)
33
+ json (~> 2.3)
34
+ parallel (~> 1.10)
35
+ parser (>= 3.1.2.1)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ regexp_parser (>= 1.8, < 3.0)
38
+ rexml (>= 3.2.5, < 4.0)
39
+ rubocop-ast (>= 1.24.1, < 2.0)
40
+ ruby-progressbar (~> 1.7)
41
+ unicode-display_width (>= 1.4.0, < 3.0)
42
+ rubocop-ast (1.24.1)
43
+ parser (>= 3.1.1.0)
44
+ ruby-progressbar (1.11.0)
45
+ unicode-display_width (2.4.2)
46
+
47
+ PLATFORMS
48
+ x86_64-linux
49
+
50
+ DEPENDENCIES
51
+ rake (~> 13.0)
52
+ rspec (~> 3.0)
53
+ rubocop (~> 1.21)
54
+ to_stars!
55
+
56
+ BUNDLED WITH
57
+ 2.3.16
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Matthew Schultz
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,100 @@
1
+ # ToStars
2
+
3
+ A simple library for adding star-ratings to numeric types in ruby.
4
+
5
+ ## Installation
6
+
7
+ Install the gem and add to the application's Gemfile by executing:
8
+
9
+ $ bundle add to_stars
10
+
11
+ If bundler is not being used to manage dependencies, install the gem by executing:
12
+
13
+ $ gem install to_stars
14
+
15
+ ## Usage
16
+
17
+ By default, adds the to_stars method to Numeric.
18
+
19
+ ```
20
+ 3.to_stars #=> "★★★"
21
+ ```
22
+
23
+ Can generate a "out of" rating:
24
+
25
+ ```
26
+ 3.to_stars(5) #=> "★★★/5"
27
+ ```
28
+
29
+ ### Options
30
+
31
+ #### out_of (default: nil)
32
+
33
+ A number to set the "out of" representation. Set to nil to disable.
34
+
35
+ ```
36
+ 3.to_stars #=> "★★★"
37
+ 3.to_stars(out_of: 5) #=> "★★★/3"
38
+ 3.to_stars(out_of: nil) #=> "★★★"
39
+ ```
40
+
41
+ #### seperator (default: '/')
42
+
43
+ Defines the string to use to seperate the rating and the "out of" representation:
44
+
45
+ ```
46
+ 3.to_stars(out_of: 5, seperator: ' out of ') #=> "★★★ out of 5"
47
+ ```
48
+
49
+ #### character (default: '★')
50
+
51
+ Defines the character to be used for a star:
52
+
53
+ ```
54
+ 3.to_stars(character: 'X') #=> "XXX"
55
+ 3.to_stars(character: '&#9733;') #=> "&#9733;&#9733;&#9733;"
56
+ ```
57
+
58
+ #### out_of_format (default: :numeric)
59
+
60
+ Defines the format to use to display the "out of" representation. There are 3 options:
61
+
62
+
63
+ **:character** -
64
+ Show the "out of" representation as symbols, like the character:
65
+
66
+ ```
67
+ 3.to_stars(out_of: 5, out_of_format: :numeric) #=> "★★★/★★★★★"
68
+ ```
69
+
70
+ **:one_and_numeric** -
71
+ Show the "out of" representation as a numeric representation with a symbol:
72
+
73
+ ```
74
+ 3.to_stars(out_of: 5, out_of_format: :numeric) #=> "★★★/5★"
75
+ ```
76
+
77
+ **:numeric** (default) -
78
+ Show the "out of" representation as a number:
79
+
80
+ ```
81
+ 3.to_stars(out_of: 5, out_of_format: :numeric) #=> "★★★/5"
82
+ ```
83
+
84
+ ## Development
85
+
86
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake` to run the tests and cop. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
87
+
88
+ 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`](lib/to_stars/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).
89
+
90
+ ## Contributing
91
+
92
+ Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
93
+
94
+ ## License
95
+
96
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
97
+
98
+ ## Code of Conduct
99
+
100
+ Everyone interacting in the ToStars project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require 'rubocop/rake_task'
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ToStars
4
+ VERSION = '0.1.0'
5
+ end
data/lib/to_stars.rb ADDED
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'to_stars/version'
4
+
5
+ # Config options for the to_stars method
6
+ module ToStars
7
+ # rubocop:disable Style/ClassVars, Style/ClassVars
8
+ class Error < StandardError; end
9
+ @@character = 9733.chr(Encoding::UTF_8)
10
+ @@seperator = '/'
11
+ @@out_of_format = :numeric
12
+ @@out_of = nil
13
+
14
+ def self.character=(value)
15
+ @@character = value
16
+ end
17
+
18
+ def self.character
19
+ @@character
20
+ end
21
+
22
+ def self.seperator=(value)
23
+ @@seperator = value
24
+ end
25
+
26
+ def self.seperator
27
+ @@seperator
28
+ end
29
+
30
+ def self.out_of_format=(value)
31
+ @@out_of_format = value
32
+ end
33
+
34
+ def self.out_of_format
35
+ @@out_of_format
36
+ end
37
+
38
+ def self.out_of=(value)
39
+ @@out_of = value
40
+ end
41
+
42
+ def self.out_of
43
+ @@out_of
44
+ end
45
+ # rubocop:enable Style/ClassVars, Style/ClassVars
46
+ end
47
+
48
+ # Adds to_stars to numeric
49
+ class Numeric
50
+ def to_stars(options = {})
51
+ char, seperator, out_of, out_of_format = parse_options_for_to_stars options
52
+
53
+ string_output = ''
54
+ times do |_t|
55
+ string_output += char
56
+ end
57
+ unless out_of.nil?
58
+ string_output += seperator
59
+ case out_of_format
60
+ when :character
61
+ out_of.times do |_t|
62
+ string_output += char
63
+ end
64
+ when :one_and_numeric
65
+ string_output += out_of.to_s
66
+ string_output += char
67
+ when :numeric
68
+ string_output += out_of.to_s
69
+ end
70
+ end
71
+ string_output
72
+ end
73
+ alias stars to_stars
74
+
75
+ private
76
+
77
+ def parse_options_for_to_stars(options)
78
+ [
79
+ options.delete(:character) || ToStars.character,
80
+ options.delete(:seperator) || ToStars.seperator,
81
+ options.delete(:out_of) || ToStars.out_of,
82
+ options.delete(:out_of_format) || ToStars.out_of_format
83
+ ]
84
+ end
85
+ end
data/sig/to_stars.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module ToStars
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
data/to_stars.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/to_stars/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'to_stars'
7
+ spec.version = ToStars::VERSION
8
+ spec.authors = ['Matthew Schultz']
9
+ # spec.email = ["TODO: Write your email address"]
10
+
11
+ spec.summary = 'Adds .to_stars to numeric to generate a rating representation.'
12
+ spec.description = 'Adds .to_stars to numeric to generate a rating representation.'
13
+ spec.homepage = 'https://github.com/MatthewSchultz/to_stars'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 2.6.0'
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
+
19
+ spec.metadata['homepage_uri'] = spec.homepage
20
+ spec.metadata['source_code_uri'] = 'https://github.com/MatthewSchultz/to_stars'
21
+ spec.metadata['changelog_uri'] = "#{spec.homepage}/blob/main/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(__dir__) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
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
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: to_stars
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Schultz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2023-01-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Adds .to_stars to numeric to generate a rating representation.
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - ".rspec"
20
+ - ".rubocop.yml"
21
+ - CHANGELOG.md
22
+ - CODE_OF_CONDUCT.md
23
+ - Gemfile
24
+ - Gemfile.lock
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/to_stars.rb
29
+ - lib/to_stars/version.rb
30
+ - sig/to_stars.rbs
31
+ - to_stars.gemspec
32
+ homepage: https://github.com/MatthewSchultz/to_stars
33
+ licenses:
34
+ - MIT
35
+ metadata:
36
+ homepage_uri: https://github.com/MatthewSchultz/to_stars
37
+ source_code_uri: https://github.com/MatthewSchultz/to_stars
38
+ changelog_uri: https://github.com/MatthewSchultz/to_stars/blob/main/CHANGELOG.md
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.6.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.3.7
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Adds .to_stars to numeric to generate a rating representation.
58
+ test_files: []