electric 0.0.5 → 0.0.6

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +26 -15
  3. data/lib/electric/ohm.rb +18 -6
  4. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35f89c80c18ec3cc1bb84c36880b42c2ab55c0a0
4
- data.tar.gz: 050c9b402d0b7a7448664818684edd1c5b7446b5
3
+ metadata.gz: 6e5e899ace0fa71416ddd00da6fdbc80381b669e
4
+ data.tar.gz: e9c95ce9bfe4c5e1015280d85896fb6ed93cd1be
5
5
  SHA512:
6
- metadata.gz: faf6ba1905bf0c341b0962c814bc3b396874c4e84a3b99678738481b014da3fdfff690d69a062ef3aafdaf759d515fdf9073f76e24bcf66b0208b7423caf87f6
7
- data.tar.gz: d10ed648975f54ab0b746a8b1334f40c4ddc84652750cca713d011ce99afc1c34173f8663966a1ab8726b2e8a62b112e143ac78b9eae374768023444119c8ae8
6
+ metadata.gz: 381903b6d0d603e639cc9ec2feedbd17b79b7f7f62d1895f3b2860a3a09e19ab9aa7cd8a0bf0890ce1b023d033c5785754ebc97eee2b8d15431eab037681dbe0
7
+ data.tar.gz: 1008154b07de3d0c1b551224fc12837a38c655b8954aef67c8868099d4679a1db928939476a39c187fdfaef636135bfe7f215d4e31c8c7f4961e45c9f3456dd4
data/README.md CHANGED
@@ -1,16 +1,25 @@
1
1
  ## Ruby Library for electronics
2
2
 
3
+ ### Setup
4
+
5
+ gem install electric
6
+
7
+ irb
8
+
9
+ require 'electric'
10
+
3
11
  ### Resistor Color Code Calculator
4
12
 
5
13
  Accepts 4 arguments (first 3 bands determine resistor value, 4th band is for tolerance %), though none are required to return a value of 0 ohms. You must preserve order of bands as arguments.
6
14
 
7
- resistor = Electric::Resistor.new("red", "black", "brown")
8
- resistor.value
9
- => 200
10
- resistor.tolerance
11
- => "5%"
12
- resistor.human_readable
13
- => "200 ohms, +/- 5%"
15
+ resistor = Electric::Resistor.new("red", "black", "brown")
16
+
17
+ resistor.value
18
+ => 200
19
+ resistor.tolerance
20
+ => "5%"
21
+ resistor.human_readable
22
+ => "200 ohms, +/- 5%"
14
23
 
15
24
  ### Ohm's Law Calculator
16
25
 
@@ -18,14 +27,16 @@ Accepts 4 named arguments: "volts", "ohms", "amps", and "watts" in any order. Yo
18
27
 
19
28
  There are 4 methods that can be called to run calculations: "resistance", "power", "voltage", and "current"
20
29
 
21
- Electric::Ohm.new(:volts => 5, :ohms => 330).voltage
22
- => 5.0
23
- Electric::Ohm.new(:volts => 5, :ohms => 330).resistance
24
- => 330.0
25
- Electric::Ohm.new(:volts => 5, :ohms => 330).current
26
- => 0.015151515151515152
27
- Electric::Ohm.new(:volts => 5, :ohms => 330).power
28
- => 0.07575757575757576
30
+ ohm = Electric::Ohm.new(:volts => 5, :ohms => 330)
31
+
32
+ ohm.voltage
33
+ => 5.0
34
+ ohm.resistance
35
+ => 330.0
36
+ ohm.current
37
+ => 0.015151515151515152
38
+ ohm.power
39
+ => 0.07575757575757576
29
40
 
30
41
 
31
42
  More documentation on the way...
@@ -4,10 +4,15 @@ module Electric
4
4
  attr_accessor :ohms, :volts, :amps, :watts
5
5
 
6
6
  def initialize(options={})
7
- @ohms = options[:ohms].to_f if options[:ohms]
8
- @volts = options[:volts].to_f if options[:volts]
9
- @amps = options[:amps].to_f if options[:amps]
10
- @watts = options[:watts].to_f if options[:watts]
7
+ ohms = options["ohms"] || options[:ohms] || options["resistance"] || options[:resistance]
8
+ @ohms = ohms.to_f if ohms.present?
9
+ volts = options["volts"] || options[:volts] || options["voltage"] || options[:voltage]
10
+ @volts = volts.to_f if volts.present?
11
+ amps = options["amps"] || options[:amps] || options["current"] || options[:current] || options["amperage"] || options[:amperage]
12
+ @amps = amps.to_f if amps.present?
13
+ watts = options["watts"] || options[:watts] || options["power"] || options[:power]
14
+ @watts = watts.to_f if watts.present?
15
+ calculate
11
16
  end
12
17
 
13
18
  def resistance
@@ -26,6 +31,13 @@ module Electric
26
31
  watts ? watts : get_power
27
32
  end
28
33
 
34
+ def calculate
35
+ @ohms = get_resistance unless @ohms
36
+ @volts = get_voltage unless @volts
37
+ @amps = get_current unless @amps
38
+ @watts = get_power unless @watts
39
+ end
40
+
29
41
  private
30
42
 
31
43
  def get_resistance
@@ -52,7 +64,7 @@ module Electric
52
64
  watts / amps
53
65
  elsif ohms && watts
54
66
  # sq_root(P * R)
55
- sqrt(watts * ohms)
67
+ Math.sqrt(watts * ohms)
56
68
  else
57
69
  volts if volts
58
70
  end
@@ -67,7 +79,7 @@ module Electric
67
79
  volts / ohms
68
80
  elsif watts && ohms
69
81
  # sq_root(P) / R
70
- sqrt(watts) / ohms
82
+ Math.sqrt(watts) / ohms
71
83
  else
72
84
  amps if amps
73
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: electric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - JD Warren
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-07 00:00:00.000000000 Z
11
+ date: 2014-08-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby library for calculating things like ohms law, resistor values, etc..
14
14
  email:
@@ -17,14 +17,14 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
+ - MIT-LICENSE
21
+ - README.md
22
+ - Rakefile
23
+ - lib/electric.rb
20
24
  - lib/electric/base.rb
21
25
  - lib/electric/ohm.rb
22
26
  - lib/electric/resistor.rb
23
- - lib/electric.rb
24
27
  - lib/tasks/edmunds_ruby_tasks.rake
25
- - MIT-LICENSE
26
- - Rakefile
27
- - README.md
28
28
  homepage: https://github.com/johndavid400/electric
29
29
  licenses: []
30
30
  metadata: {}
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  version: '0'
45
45
  requirements: []
46
46
  rubyforge_project:
47
- rubygems_version: 2.0.14
47
+ rubygems_version: 2.3.0
48
48
  signing_key:
49
49
  specification_version: 4
50
50
  summary: Electronics formulas