electric 0.0.1 → 0.0.2

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/lib/electric/ohm.rb +73 -0
  3. data/lib/electric.rb +1 -0
  4. metadata +7 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f71842c31a619ffdc9bc8b14a1d05814b449c100
4
- data.tar.gz: 5a2cd9cabbdd4cbbfcfa4cd7dca10ce18388d060
3
+ metadata.gz: 6ad0755a1e166660547c5e4187bc67e2784e0806
4
+ data.tar.gz: 88d2ab3e34e57b6d062d576382614fc8c9598bd8
5
5
  SHA512:
6
- metadata.gz: fc157dabf355181c56fe6fdfc71de9e6c584543b6e0f7b9499894e5e28c9bba5bfc2f87dbb5813093d7f94978046d7f0a96fcb73603f593ab9ce9f6503422512
7
- data.tar.gz: 6d50e446caa9fc651b316365395fc4ec4853c59b1853d46507765a2b33288ee4e5de60f5f4f8b783eab90fb793f24e88589aa0402a902f18099f69b87d137027
6
+ metadata.gz: 74fe8af5df23d26303978bb00454f4f530192678fcf933e01048432a606916255df8891f3aaa3d45d8092b80083fa0fcde0e45b420196a4bb5f28e22e5a06974
7
+ data.tar.gz: 4b380bad22ec76072cdffb3f511bbaade1daf1d456b02398f0decbe282ef4c7829bcbaf5bc0d95a19eaeab945a787375f3ec2b48e185ad84b6c7c9c10c3e636f
@@ -0,0 +1,73 @@
1
+ module Electric
2
+ class Ohm
3
+ attr_accessor :ohms, :volts, :amps, :watts
4
+
5
+ def initialize(options={})
6
+ @ohms = options[:ohms].to_f if options[:ohms]
7
+ @volts = options[:volts].to_f if options[:volts]
8
+ @amps = options[:amps].to_f if options[:amps]
9
+ @watts = options[:watts].to_f if options[:watts]
10
+ end
11
+
12
+ def resistance
13
+ if watts && amps
14
+ # P / I^2
15
+ watts / (amps * amps)
16
+ elsif volts && amps
17
+ # V / I
18
+ volts / amps
19
+ elsif volts && watts
20
+ # V^2 / P
21
+ (volts * volts) / watts
22
+ else
23
+ ohms if ohms
24
+ end
25
+ end
26
+
27
+ def voltage
28
+ if ohms && amps
29
+ # I * R
30
+ amps * ohms
31
+ elsif watts && amps
32
+ # P / I^2
33
+ watts / (amps * amps)
34
+ elsif ohms && watts
35
+ # sq_root(P * R)
36
+ sqrt(watts * ohms)
37
+ else
38
+ volts if volts
39
+ end
40
+ end
41
+
42
+ def current
43
+ if watts && volts
44
+ # P / V
45
+ watts / volts
46
+ elsif volts && ohms
47
+ # V / R
48
+ volts / ohms
49
+ elsif watts && ohms
50
+ # sq_root(P) / R
51
+ sqrt(watts) / ohms
52
+ else
53
+ amps if amps
54
+ end
55
+ end
56
+
57
+ def power
58
+ if volts && amps
59
+ # V * I
60
+ volts * amps
61
+ elsif volts && ohms
62
+ # V^2 / R
63
+ (volts * volts) / ohms
64
+ elsif amps && ohms
65
+ # I^2 * R
66
+ (amps * amps) * ohms
67
+ else
68
+ watts if watts
69
+ end
70
+ end
71
+
72
+ end
73
+ end
data/lib/electric.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  require 'electric/resistor'
2
+ require 'electric/ohm'
2
3
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: electric
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - JD Warren
@@ -17,13 +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
24
20
  - lib/electric/base.rb
21
+ - lib/electric/ohm.rb
25
22
  - lib/electric/resistor.rb
23
+ - lib/electric.rb
26
24
  - lib/tasks/edmunds_ruby_tasks.rake
25
+ - MIT-LICENSE
26
+ - Rakefile
27
+ - README.md
27
28
  homepage: https://github.com/johndavid400/electric
28
29
  licenses: []
29
30
  metadata: {}
@@ -43,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
43
44
  version: '0'
44
45
  requirements: []
45
46
  rubyforge_project:
46
- rubygems_version: 2.3.0
47
+ rubygems_version: 2.0.14
47
48
  signing_key:
48
49
  specification_version: 4
49
50
  summary: Electronics formulas