mod_baby 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mod_baby.gemspec
4
+ gemspec
5
+ gem 'rspec'
6
+ gem 'highline'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 cpeak
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.
@@ -0,0 +1,28 @@
1
+ # ModBaby
2
+ This is a modular scale gem, written as a learning assignment for my second residency.
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'mod_baby'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install mod_baby
17
+
18
+ ## Usage
19
+
20
+ From your command line simply type 'mod'
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/mod ADDED
@@ -0,0 +1,17 @@
1
+ require "mod_baby"
2
+ require "cli"
3
+ require "highline/import"
4
+
5
+ Cli.clear_screen
6
+
7
+ base = ask("What is your base font size? ", Integer) { |q| q.in = 1..100 }
8
+ Cli.clear_screen
9
+
10
+ puts "#{ModBaby::Choices.list}"
11
+
12
+ ratio = ask("With a base font size of #{base}, what scale do you want to use? ", Integer) { |q| q.in = 1..7 }
13
+ Cli.clear_screen
14
+
15
+ ratios = ModBaby::ModularScale.calculate_scale(base, ratio)
16
+ puts "Pixels: #{ratios.keys.join(', ')}"
17
+ puts "Ems : #{ratios.values.join(', ')}"
@@ -0,0 +1,7 @@
1
+ require "mod_baby/version"
2
+
3
+ module Cli
4
+ def self.clear_screen
5
+ system "clear"
6
+ end
7
+ end
@@ -0,0 +1,52 @@
1
+ require "mod_baby/version"
2
+
3
+ module ModBaby
4
+
5
+ class Ratio
6
+ attr_reader :name, :value
7
+
8
+ def initialize(name, value)
9
+ @name = name
10
+ @value = value
11
+ end
12
+
13
+ def steps(base)
14
+ (base * @value)
15
+ end
16
+ end
17
+
18
+ Ratios = [
19
+ Ratio.new("Golden Ratio", 1.618),
20
+ Ratio.new("Perfect Fourth", 1.333),
21
+ Ratio.new("Perfect Fifth", 1.5),
22
+ Ratio.new("Major Third", 1.25),
23
+ Ratio.new("Minor Third", 1.2),
24
+ Ratio.new("Octave", 2),
25
+ Ratio.new("Double Octave", 4)
26
+ ]
27
+
28
+ class Choices
29
+ def self.list
30
+ choices = []
31
+ Ratios.each_with_index do |choice, i|
32
+ choices << "#{i+1}. #{choice.name}"
33
+ end
34
+ return choices.join("\n")
35
+ end
36
+ end
37
+
38
+ class ModularScale
39
+ def self.calculate_scale(base, ratio_choice)
40
+ ratio = Ratios[ratio_choice - 1]
41
+ results = {base => 1}
42
+ ems = 1
43
+
44
+ 6.times do
45
+ base = ratio.steps(base).round(3)
46
+ ems = ratio.steps(ems).round(3)
47
+ results[base] = ems
48
+ end
49
+ return results
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module ModBaby
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mod_baby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mod_baby"
8
+ spec.version = ModBaby::VERSION
9
+ spec.authors = ["cpeak"]
10
+ spec.email = ["chris@8thlight.com"]
11
+ spec.description = %q{"A quick tool for using the Modular Scale"}
12
+ spec.summary = %q{"A quick tool for using the Modular Scale"}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe ModBaby do
4
+ it 'initializes a new ratio hash' do
5
+ @new_hash = ModBaby::Ratio.new("Ratio Name", "42")
6
+ @new_hash.name.should == "Ratio Name"
7
+ @new_hash.value.should == "42"
8
+ end
9
+
10
+ it 'has equal number of choices and ratios' do
11
+ ModBaby::Choices.list.split("\n").length.should == ModBaby::Ratios.count
12
+ end
13
+
14
+ it 'returns the steps in the modular scale in pixels' do
15
+ ModBaby::ModularScale.calculate_scale(10,2).keys.should include(13.33)
16
+ end
17
+
18
+ it 'returns the steps in the modular scale in ems' do
19
+ ModBaby::ModularScale.calculate_scale(17,1).values.should include(2.618)
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'mod_baby'
5
+
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mod_baby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - cpeak
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
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: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
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: '0'
46
+ description: ! '"A quick tool for using the Modular Scale"'
47
+ email:
48
+ - chris@8thlight.com
49
+ executables:
50
+ - mod
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - bin/mod
60
+ - lib/cli.rb
61
+ - lib/mod_baby.rb
62
+ - lib/mod_baby/version.rb
63
+ - mod_baby.gemspec
64
+ - spec/mod_spec.rb
65
+ - spec/spec_helper.rb
66
+ homepage: ''
67
+ licenses:
68
+ - MIT
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 1.8.24
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: ! '"A quick tool for using the Modular Scale"'
91
+ test_files:
92
+ - spec/mod_spec.rb
93
+ - spec/spec_helper.rb