unicode_math 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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .rvmrc
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ script: rspec
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Steve Richert
2
+
3
+ MIT License
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,74 @@
1
+ # unicode_math ☻ [![Build Status](https://secure.travis-ci.org/collectiveidea/unicode_math.png)](http://travis-ci.org/collectiveidea/unicode_math) [![Dependency Status](https://gemnasium.com/collectiveidea/unicode_math.png)](https://gemnasium.com/collectiveidea/unicode_math) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/collectiveidea/unicode_math)
2
+
3
+ You can have lots of fun with unicode in Ruby. Here are a few ways, and we'd love to see more!
4
+
5
+ ## Usage
6
+
7
+ ### Fractions
8
+
9
+ You can use many fractions as literals:
10
+
11
+ ⅞ * 5
12
+ 30 + ½
13
+ ⅖ / ⅙
14
+
15
+ ### Roots
16
+
17
+ You can use square root, cube root, and fourth root:
18
+
19
+ √ 4
20
+ ∛ 27
21
+ ∜ 81
22
+
23
+ ### Trigonometry
24
+
25
+ There's a sine wave unicode character, so we can calculate sine of a number:
26
+
27
+ ∿ π/2
28
+
29
+ ### Constants
30
+
31
+ Easily use unicode costants:
32
+
33
+ π
34
+ τ
35
+ 𝑒
36
+
37
+
38
+ And have fun with them:
39
+
40
+ (-∞..∞).cover? ∞ + 1
41
+
42
+ ### Exponents
43
+
44
+ You can raise to the powers of 0–9 as well as arbitrary numbers:
45
+
46
+ 2.⁷
47
+ 1.617 * 10.ⁿ(13)
48
+
49
+ ### Division
50
+
51
+ 21.÷ 7
52
+ 6.⟌ 24
53
+
54
+ ## Installation
55
+
56
+ Add this line to your application's Gemfile:
57
+
58
+ gem 'unicode_math'
59
+
60
+ And then execute:
61
+
62
+ $ bundle
63
+
64
+ Or install it yourself as:
65
+
66
+ $ gem install unicode_math
67
+
68
+ ## Contributing
69
+
70
+ 1. Fork it
71
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
72
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
73
+ 4. Push to the branch (`git push origin my-new-feature`)
74
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ module UnicodeMath
4
+ module Constants
5
+ def self.included(base)
6
+ base.class_eval do
7
+ %w(π ϖ 𝛑 𝛡 𝜋 𝜛 𝝅 𝝕 𝝿 𝞏 𝞹 𝟉).each do |pi|
8
+ define_method(pi) do
9
+ Math::PI
10
+ end
11
+ end
12
+
13
+ %w(τ 𝛕 𝜏 𝝉 𝞃 𝞽).each do |tau|
14
+ define_method(tau) do
15
+ 2 * Math::PI
16
+ end
17
+ end
18
+
19
+ %w(ℯ 𝐞 𝑒 𝒆 𝖾 𝗲 𝘦 𝙚 𝚎 e).each do |e|
20
+ define_method(e) do
21
+ Math::E
22
+ end
23
+ end
24
+
25
+ define_method('∞') do
26
+ 1.0 / 0
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ Kernel.send(:include, UnicodeMath::Constants)
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ module UnicodeMath
4
+ module Division
5
+ def self.included(base)
6
+ base.class_eval do
7
+ define_method('÷') do |divisor|
8
+ self / divisor
9
+ end
10
+
11
+ define_method('⟌') do |dividend|
12
+ dividend / self
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ Numeric.send(:include, UnicodeMath::Division)
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+
3
+ module UnicodeMath
4
+ module Exponents
5
+ def self.included(base)
6
+ base.class_eval do
7
+ define_method('⁰') do
8
+ 1
9
+ end
10
+
11
+ define_method('¹') do
12
+ self
13
+ end
14
+
15
+ define_method('²') do
16
+ self ** 2
17
+ end
18
+
19
+ define_method('³') do
20
+ self ** 3
21
+ end
22
+
23
+ define_method('⁴') do
24
+ self ** 4
25
+ end
26
+
27
+ define_method('⁵') do
28
+ self ** 5
29
+ end
30
+
31
+ define_method('⁶') do
32
+ self ** 6
33
+ end
34
+
35
+ define_method('⁷') do
36
+ self ** 7
37
+ end
38
+
39
+ define_method('⁸') do
40
+ self ** 8
41
+ end
42
+
43
+ define_method('⁹') do
44
+ self ** 9
45
+ end
46
+
47
+ %w(ⁿ ⁱ).each do |exponent|
48
+ define_method(exponent) do |power|
49
+ self ** power
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ Numeric.send(:include, UnicodeMath::Exponents)
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ module UnicodeMath
4
+ module Fractions
5
+ def self.included(base)
6
+ base.class_eval do
7
+ # Half
8
+ define_method '½' do
9
+ 0.5
10
+ end
11
+
12
+ # Thirds
13
+ define_method '⅓' do
14
+ 1.0 / 3
15
+ end
16
+
17
+ define_method '⅔' do
18
+ 2.0 / 3
19
+ end
20
+
21
+ # Quarters
22
+ define_method '¼' do
23
+ 0.25
24
+ end
25
+
26
+ define_method '¾' do
27
+ 0.75
28
+ end
29
+
30
+ # Fifths
31
+ define_method '⅕' do
32
+ 0.2
33
+ end
34
+
35
+ define_method '⅖' do
36
+ 0.4
37
+ end
38
+
39
+ define_method '⅗' do
40
+ 0.6
41
+ end
42
+
43
+ define_method '⅘' do
44
+ 0.8
45
+ end
46
+
47
+ # Sixths
48
+ define_method '⅙' do
49
+ 1.0 / 6
50
+ end
51
+
52
+ define_method '⅚' do
53
+ 5.0 / 6
54
+ end
55
+
56
+ # Eighths
57
+ define_method '⅛' do
58
+ 0.125
59
+ end
60
+
61
+ define_method '⅜' do
62
+ 0.375
63
+ end
64
+
65
+ define_method '⅝' do
66
+ 0.625
67
+ end
68
+
69
+ define_method '⅞' do
70
+ 0.875
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ Kernel.send(:include, UnicodeMath::Fractions)
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ module UnicodeMath
4
+ module Roots
5
+ def self.included(base)
6
+ base.class_eval do
7
+
8
+ define_method('√') do |number|
9
+ Math.sqrt number
10
+ end
11
+
12
+ define_method('∛') do |number|
13
+ Math.cbrt number
14
+ end
15
+
16
+ define_method('∜') do |number|
17
+ number ** 0.25
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ Kernel.send :include, UnicodeMath::Roots
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ module UnicodeMath
4
+ module Trigonometry
5
+ def self.included(base)
6
+ base.class_eval do
7
+
8
+ define_method('∿') do |number|
9
+ Math.sin number
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
16
+
17
+ Kernel.send :include, UnicodeMath::Trigonometry
@@ -0,0 +1 @@
1
+ Dir[File.expand_path('../unicode_math/*.rb', __FILE__)].each{|f| require f }
@@ -0,0 +1,3 @@
1
+ require 'unicode_math'
2
+
3
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each{|f| require f }
@@ -0,0 +1,3 @@
1
+ RSpec.configure do |config|
2
+ config.order = 'random'
3
+ end
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe UnicodeMath::Constants do
6
+ it 'defines π' do
7
+ expect(π).to be_within(0.00005).of(3.1416)
8
+ end
9
+
10
+ it 'defines τ' do
11
+ expect(τ).to eq(2 * π)
12
+ end
13
+
14
+ it 'defines 𝑒' do
15
+ expect(𝑒).to be_within(0.00005).of(2.7183)
16
+ end
17
+
18
+ it 'defines ∞' do
19
+ expect(∞ + 1).to eq(∞)
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe UnicodeMath::Division do
6
+ it 'divides' do
7
+ expect(21.÷ 7).to eq(3)
8
+ end
9
+
10
+ it 'long divides' do
11
+ expect(7.⟌ 56).to eq(8)
12
+ end
13
+ end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe UnicodeMath::Exponents do
6
+ it 'raises to the zero power' do
7
+ expect(2.⁰).to eq(1)
8
+ end
9
+
10
+ it 'raises to the first power' do
11
+ expect(2.¹).to eq(2)
12
+ end
13
+
14
+ it 'squares' do
15
+ expect(2.²).to eq(4)
16
+ end
17
+
18
+ it 'cubes' do
19
+ expect(2.³).to eq(8)
20
+ end
21
+
22
+ it 'raises to the fourth power' do
23
+ expect(2.⁴).to eq(16)
24
+ end
25
+
26
+ it 'raises to the fifth power' do
27
+ expect(2.⁵).to eq(32)
28
+ end
29
+
30
+ it 'raises to the sixth power' do
31
+ expect(2.⁶).to eq(64)
32
+ end
33
+
34
+ it 'raises to the seventh power' do
35
+ expect(2.⁷).to eq(128)
36
+ end
37
+
38
+ it 'raises to the eigth power' do
39
+ expect(2.⁸).to eq(256)
40
+ end
41
+
42
+ it 'raises to the ninth power' do
43
+ expect(2.⁹).to eq(512)
44
+ end
45
+
46
+ it 'raises to an arbitrary power' do
47
+ expect(2.ⁿ(10)).to eq(1024)
48
+ expect(2.ⁱ(11)).to eq(2048)
49
+ end
50
+ end
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe UnicodeMath::Fractions do
6
+ it 'defines ½ to equal 0.5' do
7
+ expect(½).to eq(0.5)
8
+ end
9
+
10
+ describe 'thirds' do
11
+ it 'defines ⅓ to equal one third' do
12
+ expect(⅓).to be_within(0.00001).of(0.33333)
13
+ end
14
+
15
+ it 'defines ⅔ to equal two thirds' do
16
+ expect(⅔).to be_within(0.00001).of(0.66666)
17
+ end
18
+ end
19
+
20
+ describe 'quarters' do
21
+ it 'defines ¼ to equal 0.25' do
22
+ expect(¼).to eq(0.25)
23
+ end
24
+
25
+ it 'defines ¾ to equal 0.75' do
26
+ expect(¾).to eq(0.75)
27
+ end
28
+ end
29
+
30
+ describe 'fifths' do
31
+ it 'defines ⅕ to equal 0.2' do
32
+ expect(⅕).to eq(0.2)
33
+ end
34
+
35
+ it 'defines ⅖ to equal 0.4' do
36
+ expect(⅖).to eq(0.4)
37
+ end
38
+
39
+ it 'defines ⅗ to equal 0.6' do
40
+ expect(⅗).to eq(0.6)
41
+ end
42
+
43
+ it 'defines ⅘ to equal 0.8' do
44
+ expect(⅘).to eq(0.8)
45
+ end
46
+ end
47
+
48
+ describe 'sixths' do
49
+ it 'defines ⅙ to equal one sixth' do
50
+ expect(⅙).to be_within(0.00001).of(0.16666)
51
+ end
52
+
53
+ it 'defines ⅚ to equal five sixths' do
54
+ expect(⅚).to be_within(0.00001).of(0.83333)
55
+ end
56
+ end
57
+
58
+ describe 'eighths' do
59
+ it 'defines ⅛ to equal 0.125' do
60
+ expect(⅛).to eq(0.125)
61
+ end
62
+
63
+ it 'defines ⅜ to equal 0.375' do
64
+ expect(⅜).to eq(0.375)
65
+ end
66
+
67
+ it 'defines ⅝ to equal 0.625' do
68
+ expect(⅝).to eq(0.625)
69
+ end
70
+
71
+ it 'defines ⅞ to equal 0.875' do
72
+ expect(⅞).to eq(0.875)
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe UnicodeMath::Roots do
6
+ it 'defines √ to take square roots' do
7
+ result = √ 25
8
+ expect(result).to eq(5.0)
9
+ end
10
+
11
+ it 'defines ∛ to take square roots' do
12
+ result = ∛ 8
13
+ expect(result).to eq(2)
14
+ end
15
+
16
+ it 'defines ∜ to take square roots' do
17
+ result = ∜ 81
18
+ expect(result).to eq(3)
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe UnicodeMath::Trigonometry do
6
+ it 'defines ∿ to take sine of a number' do
7
+ result = ∿ Math::PI/2
8
+ expect(result).to eq(1.0)
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe UnicodeMath do
4
+ it 'is awesome'
5
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'unicode_math'
5
+ gem.version = '1.0.0'
6
+
7
+ gem.author = 'Collective Idea'
8
+ gem.email = 'info@collectiveidea.com'
9
+ gem.description = %(Fun Ruby extensions for doing math with Unicode)
10
+ gem.summary = gem.description
11
+ gem.homepage = 'https://github.com/collectiveidea/unicode_math'
12
+
13
+ gem.add_development_dependency 'rake', '~> 0.9'
14
+ gem.add_development_dependency 'rspec', '~> 2.11'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.test_files = gem.files.grep(/^spec/)
18
+ gem.require_path = 'lib'
19
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unicode_math
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Collective Idea
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '0.9'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '2.11'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '2.11'
46
+ description: Fun Ruby extensions for doing math with Unicode
47
+ email: info@collectiveidea.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - .travis.yml
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - lib/unicode_math.rb
59
+ - lib/unicode_math/constants.rb
60
+ - lib/unicode_math/division.rb
61
+ - lib/unicode_math/exponents.rb
62
+ - lib/unicode_math/fractions.rb
63
+ - lib/unicode_math/roots.rb
64
+ - lib/unicode_math/trigonometry.rb
65
+ - spec/spec_helper.rb
66
+ - spec/support/random.rb
67
+ - spec/unicode_math/constants_spec.rb
68
+ - spec/unicode_math/division_spec.rb
69
+ - spec/unicode_math/exponents_spec.rb
70
+ - spec/unicode_math/fractions_spec.rb
71
+ - spec/unicode_math/root_spec.rb
72
+ - spec/unicode_math/trigonometry_spec.rb
73
+ - spec/unicode_math_spec.rb
74
+ - unicode_math.gemspec
75
+ homepage: https://github.com/collectiveidea/unicode_math
76
+ licenses: []
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ segments:
88
+ - 0
89
+ hash: -2467562498706085623
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ segments:
97
+ - 0
98
+ hash: -2467562498706085623
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 1.8.24
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Fun Ruby extensions for doing math with Unicode
105
+ test_files:
106
+ - spec/spec_helper.rb
107
+ - spec/support/random.rb
108
+ - spec/unicode_math/constants_spec.rb
109
+ - spec/unicode_math/division_spec.rb
110
+ - spec/unicode_math/exponents_spec.rb
111
+ - spec/unicode_math/fractions_spec.rb
112
+ - spec/unicode_math/root_spec.rb
113
+ - spec/unicode_math/trigonometry_spec.rb
114
+ - spec/unicode_math_spec.rb