electric 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f71842c31a619ffdc9bc8b14a1d05814b449c100
4
+ data.tar.gz: 5a2cd9cabbdd4cbbfcfa4cd7dca10ce18388d060
5
+ SHA512:
6
+ metadata.gz: fc157dabf355181c56fe6fdfc71de9e6c584543b6e0f7b9499894e5e28c9bba5bfc2f87dbb5813093d7f94978046d7f0a96fcb73603f593ab9ce9f6503422512
7
+ data.tar.gz: 6d50e446caa9fc651b316365395fc4ec4853c59b1853d46507765a2b33288ee4e5de60f5f4f8b783eab90fb793f24e88589aa0402a902f18099f69b87d137027
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 JD Warren
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ ## Ruby Library for electronics
2
+
3
+ More documentation on the way...
4
+
5
+ ## Bug reports and Pull requests
6
+
7
+ Please open an issue on Github if you find a bug, and I will address it.
8
+
9
+ If you have an improvement to submit, please fork the repo, add your code and send a pull request.
10
+
11
+
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Electric'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ Rake::TestTask.new(:test) do |t|
31
+ t.libs << 'lib'
32
+ t.libs << 'test'
33
+ t.pattern = 'test/**/*_test.rb'
34
+ t.verbose = false
35
+ end
36
+
37
+
38
+ task :default => :test
data/lib/electric.rb ADDED
@@ -0,0 +1,2 @@
1
+ require 'electric/resistor'
2
+
@@ -0,0 +1,4 @@
1
+ module Electric
2
+ class Base
3
+ end
4
+ end
@@ -0,0 +1,79 @@
1
+ module Electric
2
+ class Resistor
3
+ attr_accessor :first, :second, :third, :fourth
4
+
5
+ def initialize(first = "black", second = "black", third = "black", fourth = "gold")
6
+ @first = first
7
+ @second = second
8
+ @third = third
9
+ @fourth = fourth
10
+ end
11
+
12
+ def human_readable
13
+ if value >= 1000000
14
+ "#{round_for(value / 1000000.0)}M ohms#{color_to_tolerance(@fourth)}"
15
+ elsif value >= 1000
16
+ "#{round_for(value / 1000.0)}K ohms#{color_to_tolerance(@fourth)}"
17
+ else
18
+ "#{value} ohms#{color_to_tolerance(@fourth)}"
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def value
25
+ "#{color_to_number(first)}#{color_to_number(second)}".to_i * color_to_multiplier(third)
26
+ end
27
+
28
+ def color_to_number(color)
29
+ colors = {
30
+ "black" => 0,
31
+ "brown" => 1,
32
+ "red" => 2,
33
+ "orange" => 3,
34
+ "yellow" => 4,
35
+ "green" => 5,
36
+ "blue" => 6,
37
+ "violet" => 7,
38
+ "grey" => 8,
39
+ "gray" => 8,
40
+ "white" => 9
41
+ }
42
+ colors[color.downcase]
43
+ end
44
+
45
+ def color_to_multiplier(color)
46
+ colors = {
47
+ "black" => 1,
48
+ "brown" => 10,
49
+ "red" => 100,
50
+ "orange" => 1000,
51
+ "yellow" => 10000,
52
+ "green" => 100000,
53
+ "blue" => 1000000,
54
+ "violet" => 10000000,
55
+ "grey" => 100000000,
56
+ "gray" => 100000000,
57
+ "white" => 1000000000
58
+ }
59
+ colors[color.downcase]
60
+ end
61
+
62
+ def color_to_tolerance(color)
63
+ colors = {
64
+ "gold" => ", +/- 5%",
65
+ "silver" => ", +/- 10%"
66
+ }
67
+ colors[color.downcase]
68
+ end
69
+
70
+ def round_for(float_val)
71
+ if float_val % 1 == 0
72
+ float_val.to_i
73
+ else
74
+ float_val
75
+ end
76
+ end
77
+
78
+ end
79
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :edmunds_ruby do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: electric
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - JD Warren
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Ruby library for calculating things like ohms law, resistor values, etc..
14
+ email:
15
+ - johndavid400@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - MIT-LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - lib/electric.rb
24
+ - lib/electric/base.rb
25
+ - lib/electric/resistor.rb
26
+ - lib/tasks/edmunds_ruby_tasks.rake
27
+ homepage: https://github.com/johndavid400/electric
28
+ licenses: []
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.3.0
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: Electronics formulas
50
+ test_files: []