electric 0.0.2 → 0.0.3
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 +4 -4
- data/README.md +8 -0
- data/lib/electric/ohm.rb +22 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e42b93c0d2344a142505435d9060180946400ff9
|
4
|
+
data.tar.gz: cb91a3c18e8b5d0c1fae5f46e9c790ac3204a956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5ef98920099f681178542c99406a857203abdf367a5805992d6c196f956d815e46096798ba195e58c39e478c65ca8d74e7882acec39fe4dbd3e7d8b8f9ebd2a1
|
7
|
+
data.tar.gz: 8924f981e023074805026b83676933f21dc52e31f237a5c93234393ba50dabf12adede6e37d4afea9fea977cdf7931ef07598ff19b5a16432e9f49d12cfa5d08
|
data/README.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
## Ruby Library for electronics
|
2
2
|
|
3
|
+
### Resistor Color Code Calculator
|
4
|
+
Electric::Resistor.new("red", "black", "brown").human_readable
|
5
|
+
|
6
|
+
### Ohm's Law Calculator
|
7
|
+
Electric::Ohm.new(:volts => 5, :ohms => 330).current
|
8
|
+
|
9
|
+
|
10
|
+
|
3
11
|
More documentation on the way...
|
4
12
|
|
5
13
|
## Bug reports and Pull requests
|
data/lib/electric/ohm.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Electric
|
2
2
|
class Ohm
|
3
|
+
|
3
4
|
attr_accessor :ohms, :volts, :amps, :watts
|
4
5
|
|
5
6
|
def initialize(options={})
|
@@ -10,6 +11,24 @@ module Electric
|
|
10
11
|
end
|
11
12
|
|
12
13
|
def resistance
|
14
|
+
ohms ? ohms : get_resistance
|
15
|
+
end
|
16
|
+
|
17
|
+
def voltage
|
18
|
+
volts ? volts : get_voltage
|
19
|
+
end
|
20
|
+
|
21
|
+
def current
|
22
|
+
amps ? amps : get_current
|
23
|
+
end
|
24
|
+
|
25
|
+
def power
|
26
|
+
watts ? watts : get_power
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def get_resistance
|
13
32
|
if watts && amps
|
14
33
|
# P / I^2
|
15
34
|
watts / (amps * amps)
|
@@ -24,7 +43,7 @@ module Electric
|
|
24
43
|
end
|
25
44
|
end
|
26
45
|
|
27
|
-
def
|
46
|
+
def get_voltage
|
28
47
|
if ohms && amps
|
29
48
|
# I * R
|
30
49
|
amps * ohms
|
@@ -39,7 +58,7 @@ module Electric
|
|
39
58
|
end
|
40
59
|
end
|
41
60
|
|
42
|
-
def
|
61
|
+
def get_current
|
43
62
|
if watts && volts
|
44
63
|
# P / V
|
45
64
|
watts / volts
|
@@ -54,7 +73,7 @@ module Electric
|
|
54
73
|
end
|
55
74
|
end
|
56
75
|
|
57
|
-
def
|
76
|
+
def get_power
|
58
77
|
if volts && amps
|
59
78
|
# V * I
|
60
79
|
volts * amps
|