math_generator 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: a6ac1bf9ca39e076fe6b42d3581c9c77a379fd795817b4a363f227d0cc4df324
4
+ data.tar.gz: 6481d26d69e1b391ac5f463913eb62a360662ef216dcb3b4662e3c58b0432a41
5
+ SHA512:
6
+ metadata.gz: b6b93e4245f8152fa13905927171d23ec960ac487c93fd3074cd41f2d3badeb0169d5bfb0da40aeebd05d6cca12f967d56f0519d34397d10be1027adf4c3f464
7
+ data.tar.gz: ed4d7ecb4cd8d8e06fc7027f26b4d427cc5f056b9df92f68273e69d6a90527bcbc2eb699d3496a4e8fc70aa900337fc9221d0248f7fc35e9f68e716d02c6c722
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-07-11
4
+
5
+ ### Added
6
+ - Initial release of MathGenerator gem
7
+ - Support for generating arithmetic problems: addition, subtraction, multiplication, and division
8
+ - Support for problems with integers, decimals, and fractions
@@ -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 aemabit@gmail.com. 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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 TODO: Write your name
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,107 @@
1
+ # MathGenerator
2
+
3
+ The MathGenerator gem is a tool designed to create a wide range of mathematical problems suitable for educational purposes. It supports basic arithmetic operations such as addition, subtraction, multiplication, and division. Additionally, it can generate problems with decimals and fractions, making it versatile for different levels of difficulty.
4
+
5
+ ## Installation
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem "math_generator"
10
+ ```
11
+
12
+ And then execute:
13
+ ```bash
14
+ bundle install
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Generating Addition Problems
20
+
21
+ ```ruby
22
+ require 'math_generator'
23
+
24
+ # Problems with integers
25
+ problem = MathGenerator::Problem.generate(:addition, 1, 10)
26
+ puts problem[:problem] # Example: "3 + 7 = ?"
27
+ puts problem[:result] # Example: 10
28
+
29
+ # Problems with decimals
30
+ problem = MathGenerator::Problem.generate(:addition, 1, 10, true)
31
+ puts problem[:problem] # Example: "3.5 + 7.2 = ?"
32
+ puts problem[:result] # Example: 10.7
33
+
34
+ # Problems with fractions
35
+ problem = MathGenerator::Problem.generate(:addition, 1, 10, false, true)
36
+ puts problem[:problem] # Example: "3/4 + 2/5 = ?"
37
+ puts problem[:result] # Example: 23/20
38
+ ```
39
+
40
+ ### Generating Subtraction Problems
41
+
42
+ ```ruby
43
+ require 'math_generator'
44
+
45
+ # Problems with integers
46
+ problem = MathGenerator::Problem.generate(:subtraction, 1, 10)
47
+ puts problem[:problem] # Example: "7 - 3 = ?"
48
+ puts problem[:result] # Example: 4
49
+
50
+ # Problems with decimals
51
+ problem = MathGenerator::Problem.generate(:subtraction, 1, 10, true)
52
+ puts problem[:problem] # Example: "7.5 - 3.2 = ?"
53
+ puts problem[:result] # Example: 4.3
54
+
55
+ # Problems with fractions
56
+ problem = MathGenerator::Problem.generate(:subtraction, 1, 10, false, true)
57
+ puts problem[:problem] # Example: "3/4 - 2/5 = ?"
58
+ puts problem[:result] # Example: 7/20
59
+ ```
60
+
61
+ ### Generating Multiplication Problems
62
+
63
+ ```ruby
64
+ require 'math_generator'
65
+
66
+ # Problems with integers
67
+ problem = MathGenerator::Problem.generate(:multiplication, 1, 10)
68
+ puts problem[:problem] # Example: "3 * 7 = ?"
69
+ puts problem[:result] # Example: 21
70
+
71
+ # Problems with decimals
72
+ problem = MathGenerator::Problem.generate(:multiplication, 1, 10, true)
73
+ puts problem[:problem] # Example: "3.5 * 2.0 = ?"
74
+ puts problem[:result] # Example: 7.0
75
+
76
+ # Problems with fractions
77
+ problem = MathGenerator::Problem.generate(:multiplication, 1, 10, false, true)
78
+ puts problem[:problem] # Example: "3/4 * 2/5 = ?"
79
+ puts problem[:result] # Example: 6/20
80
+ ```
81
+
82
+ ### Generating Division Problems
83
+
84
+ ```ruby
85
+ require 'math_generator'
86
+
87
+ # Problems with integers
88
+ problem = MathGenerator::Problem.generate(:division, 1, 10)
89
+ puts problem[:problem] # Example: "8 / 4 = ?"
90
+ puts problem[:result] # Example: 2
91
+
92
+ # Problems with decimals
93
+ problem = MathGenerator::Problem.generate(:division, 1, 10, true)
94
+ puts problem[:problem] # Example: "7.5 / 2.5 = ?"
95
+ puts problem[:result] # Example: 3.0
96
+
97
+ # Problems with fractions
98
+ problem = MathGenerator::Problem.generate(:division, 1, 10, false, true)
99
+ puts problem[:problem] # Example: "3/4 / 2/5 = ?"
100
+ puts problem[:result] # Example: 15/8
101
+ ```
102
+
103
+ ## Contributing
104
+ Contribution directions go here. You can fork the repository, create a new branch, and submit a pull request for review. Please make sure to write tests for your contributions and follow the coding standards set in the project.
105
+
106
+ ## License
107
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
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 "standard/rake"
9
+
10
+ task default: %i[spec standard]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MathGenerator
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "math_generator/version"
4
+
5
+ module MathGenerator
6
+ class Error < StandardError; end
7
+
8
+ class Problem
9
+ OPERATIONS = {
10
+ addition: "+",
11
+ subtraction: "-",
12
+ multiplication: "*",
13
+ division: "/"
14
+ }
15
+
16
+ def self.generate(operation, min = 1, max = 10, decimals = false, fractions = false)
17
+ num1 = random_number(min, max, decimals, fractions)
18
+ num2 = random_number(min, max, decimals, fractions)
19
+ result = calculate_result(operation, num1, num2)
20
+
21
+ {
22
+ problem: format_problem(operation, num1, num2),
23
+ result: result
24
+ }
25
+ end
26
+
27
+ private
28
+
29
+ def self.random_number(min, max, decimals, fractions)
30
+ if fractions
31
+ "#{rand(min..max)}/#{rand(1..max)}"
32
+ elsif decimals
33
+ rand(min.to_f..max.to_f).round(2)
34
+ else
35
+ rand(min..max)
36
+ end
37
+ end
38
+
39
+ def self.calculate_result(operation, num1, num2)
40
+ if num1.is_a?(String) || num2.is_a?(String)
41
+ num1 = Rational(num1) if num1.is_a?(String)
42
+ num2 = Rational(num2) if num2.is_a?(String)
43
+ end
44
+
45
+ case operation
46
+ when :addition
47
+ num1 + num2
48
+ when :subtraction
49
+ num1 - num2
50
+ when :multiplication
51
+ num1 * num2
52
+ when :division
53
+ num1 / num2
54
+ else
55
+ raise Error, "Unsupported operation"
56
+ end
57
+ end
58
+
59
+ def self.format_problem(operation, num1, num2)
60
+ case operation
61
+ when :addition
62
+ "#{num1} + #{num2} = ?"
63
+ when :subtraction
64
+ "#{num1} - #{num2} = ?"
65
+ when :multiplication
66
+ "#{num1} * #{num2} = ?"
67
+ when :division
68
+ "#{num1} / #{num2} = ?"
69
+ else
70
+ raise Error, "Unsupported operation"
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,4 @@
1
+ module MathGenerator
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: math_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - aemabit
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-07-13 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: The MathGenerator gem is a tool designed to create a wide range of mathematical
14
+ problems suitable for educational purposes. It supports basic arithmetic operations
15
+ such as addition, subtraction, multiplication, and division. Additionally, it can
16
+ generate problems with decimals and fractions, making it versatile for different
17
+ levels of difficulty.
18
+ email:
19
+ - am@connectnodes.io
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - ".rspec"
25
+ - ".standard.yml"
26
+ - CHANGELOG.md
27
+ - CODE_OF_CONDUCT.md
28
+ - LICENSE.txt
29
+ - README.md
30
+ - Rakefile
31
+ - lib/math_generator.rb
32
+ - lib/math_generator/version.rb
33
+ - sig/math_generator.rbs
34
+ homepage: https://github.com/aemabit/math_generator
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ allowed_push_host: https://rubygems.org
39
+ homepage_uri: https://github.com/aemabit/math_generator
40
+ source_code_uri: https://github.com/aemabit/math_generator
41
+ changelog_uri: https://github.com/aemabit/math_generator/blob/main/CHANGELOG.md
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 3.0.0
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.5.9
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: A gem for generating mathematical problems including addition, subtraction,
61
+ multiplication, division, decimals, and fractions.
62
+ test_files: []