special_ratio 0.2.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 +7 -0
- data/.gitignore +14 -0
- data/.images/image.png +0 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +6 -0
- data/lib/special_ratio.rb +4 -0
- data/lib/special_ratio/ratio.rb +48 -0
- data/lib/special_ratio/ratios/golden_ratio.rb +8 -0
- data/lib/special_ratio/ratios/silver_ratio.rb +8 -0
- data/lib/special_ratio/version.rb +3 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/special_ratio_spec.rb +67 -0
- data/special_ratio.gemspec +23 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5c09a10c6c2ca600f33ebaf977c701d82c9730c9
|
4
|
+
data.tar.gz: b17a9c0cf53919310d44c5894644539c6cc9876f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3d97255229e170d9beca5137671a4ba9d16b4a7efd67fae52dd241505148a595c0f6c13bf5f849c351cb2370bc2d342bcdbe303f409dd6aa6ef7036734a4f3d
|
7
|
+
data.tar.gz: 2c32ae51160795f6654bed6e13bf8b331300da6fdf8a9bb90821eccb3492966833887a6ea39f0a36f3676025aeb0bbc8ec692b48ea32e83f3097593d47b51d03
|
data/.gitignore
ADDED
data/.images/image.png
ADDED
Binary file
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 kami30k
|
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,55 @@
|
|
1
|
+
# SpecialRatio
|
2
|
+
|
3
|
+
[](https://travis-ci.org/kami30k/special_ratio)
|
4
|
+
[](http://badge.fury.io/rb/special_ratio)
|
5
|
+
|
6
|
+
SpecialRatio is a utility for designer.
|
7
|
+
Calculate value for designing by using some classic methods.
|
8
|
+
e.g. Golden Ratio, Silver Ratio.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'special_ratio'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install special_ratio
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+

|
29
|
+
|
30
|
+
SpecialRatio has two class - GoldenRatio and SilverRatio.
|
31
|
+
It expects for receive `:long` or `:short` or `:sum` parameter.
|
32
|
+
|
33
|
+
Example of this gem is as follows:
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
golden_ratio = SpecialRatio::GoldenRatio.new(long: 100)
|
37
|
+
|
38
|
+
golden_ratio.long #=> 100
|
39
|
+
golden_ratio.short #=> 61.80469715698393
|
40
|
+
golden_ratio.sum #=> 161.80469715698393
|
41
|
+
|
42
|
+
silver_ratio = SpecialRatio::SilverRatio.new(short: 100)
|
43
|
+
|
44
|
+
silver_ratio.long #=> 141.4
|
45
|
+
silver_ratio.short #=> 100
|
46
|
+
silver_ratio.sum #=> 241.39999999999998
|
47
|
+
```
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/kami30k/special_ratio/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
module SpecialRatio
|
2
|
+
class Ratio
|
3
|
+
VALID_KEYS = [:long, :short, :sum]
|
4
|
+
|
5
|
+
def initialize(params)
|
6
|
+
params = params.select { |k, v| VALID_KEYS.include?(k) }
|
7
|
+
|
8
|
+
unless params.size == 1
|
9
|
+
raise ArgumentError, ':long or :short or :sum is required'
|
10
|
+
end
|
11
|
+
|
12
|
+
@key, @value = params.map { |k, v| [k, v] } .flatten
|
13
|
+
end
|
14
|
+
|
15
|
+
def long
|
16
|
+
case @key
|
17
|
+
when :long
|
18
|
+
@value
|
19
|
+
when :short
|
20
|
+
@value * @ratio
|
21
|
+
when :sum
|
22
|
+
@value * (@ratio / (@ratio + 1))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def short
|
27
|
+
case @key
|
28
|
+
when :long
|
29
|
+
@value / @ratio
|
30
|
+
when :short
|
31
|
+
@value
|
32
|
+
when :sum
|
33
|
+
@value / (@ratio + 1)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def sum
|
38
|
+
case @key
|
39
|
+
when :long
|
40
|
+
@value * ((@ratio + 1) / @ratio)
|
41
|
+
when :short
|
42
|
+
@value * (@ratio + 1)
|
43
|
+
when :sum
|
44
|
+
@value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SpecialRatio::Ratio do
|
4
|
+
describe 'GoldenRatio' do
|
5
|
+
context 'pass :long' do
|
6
|
+
let(:value) { SpecialRatio::GoldenRatio.new(long: 100) }
|
7
|
+
|
8
|
+
it 'should be calculated correctly' do
|
9
|
+
expect(value.long.round).to eq(100)
|
10
|
+
expect(value.short.round).to eq(62)
|
11
|
+
expect(value.sum.round).to eq(162)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'pass :short' do
|
16
|
+
let(:value) { SpecialRatio::GoldenRatio.new(short: 100) }
|
17
|
+
|
18
|
+
it 'should be calculated correctly' do
|
19
|
+
expect(value.long.round).to eq(162)
|
20
|
+
expect(value.short.round).to eq(100)
|
21
|
+
expect(value.sum.round).to eq(262)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'pass :sum' do
|
26
|
+
let(:value) { SpecialRatio::GoldenRatio.new(sum: 100) }
|
27
|
+
|
28
|
+
it 'should be calculated correctly' do
|
29
|
+
expect(value.long.round).to eq(62)
|
30
|
+
expect(value.short.round).to eq(38)
|
31
|
+
expect(value.sum.round).to eq(100)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'SilverRatio' do
|
37
|
+
context 'pass :long' do
|
38
|
+
let(:value) { SpecialRatio::SilverRatio.new(long: 100) }
|
39
|
+
|
40
|
+
it 'should be calculated correctly' do
|
41
|
+
expect(value.long.round).to eq(100)
|
42
|
+
expect(value.short.round).to eq(71)
|
43
|
+
expect(value.sum.round).to eq(171)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'pass :short' do
|
48
|
+
let(:value) { SpecialRatio::SilverRatio.new(short: 100) }
|
49
|
+
|
50
|
+
it 'should be calculated correctly' do
|
51
|
+
expect(value.long.round).to eq(141)
|
52
|
+
expect(value.short.round).to eq(100)
|
53
|
+
expect(value.sum.round).to eq(241)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'pass :sum' do
|
58
|
+
let(:value) { SpecialRatio::SilverRatio.new(sum: 100) }
|
59
|
+
|
60
|
+
it 'should be calculated correctly' do
|
61
|
+
expect(value.long.round).to eq(59)
|
62
|
+
expect(value.short.round).to eq(41)
|
63
|
+
expect(value.sum.round).to eq(100)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'special_ratio/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'special_ratio'
|
7
|
+
spec.version = SpecialRatio::VERSION
|
8
|
+
spec.authors = ['kami30k']
|
9
|
+
spec.email = ['kami30k@gmail.com']
|
10
|
+
spec.summary = %q{Calculate value for designing by using some classic methods. e.g. Golden Ratio, Silver Ratio.}
|
11
|
+
spec.description = spec.summary
|
12
|
+
spec.homepage = 'https://github.com/kami30k/special_ratio'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
21
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
22
|
+
spec.add_development_dependency 'rspec'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: special_ratio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kami30k
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Calculate value for designing by using some classic methods. e.g. Golden
|
56
|
+
Ratio, Silver Ratio.
|
57
|
+
email:
|
58
|
+
- kami30k@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".images/image.png"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE.txt
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- lib/special_ratio.rb
|
72
|
+
- lib/special_ratio/ratio.rb
|
73
|
+
- lib/special_ratio/ratios/golden_ratio.rb
|
74
|
+
- lib/special_ratio/ratios/silver_ratio.rb
|
75
|
+
- lib/special_ratio/version.rb
|
76
|
+
- spec/spec_helper.rb
|
77
|
+
- spec/special_ratio_spec.rb
|
78
|
+
- special_ratio.gemspec
|
79
|
+
homepage: https://github.com/kami30k/special_ratio
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Calculate value for designing by using some classic methods. e.g. Golden
|
103
|
+
Ratio, Silver Ratio.
|
104
|
+
test_files:
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/special_ratio_spec.rb
|