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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +8 -0
  3. data/lib/electric/ohm.rb +22 -3
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ad0755a1e166660547c5e4187bc67e2784e0806
4
- data.tar.gz: 88d2ab3e34e57b6d062d576382614fc8c9598bd8
3
+ metadata.gz: e42b93c0d2344a142505435d9060180946400ff9
4
+ data.tar.gz: cb91a3c18e8b5d0c1fae5f46e9c790ac3204a956
5
5
  SHA512:
6
- metadata.gz: 74fe8af5df23d26303978bb00454f4f530192678fcf933e01048432a606916255df8891f3aaa3d45d8092b80083fa0fcde0e45b420196a4bb5f28e22e5a06974
7
- data.tar.gz: 4b380bad22ec76072cdffb3f511bbaade1daf1d456b02398f0decbe282ef4c7829bcbaf5bc0d95a19eaeab945a787375f3ec2b48e185ad84b6c7c9c10c3e636f
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 voltage
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 current
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 power
76
+ def get_power
58
77
  if volts && amps
59
78
  # V * I
60
79
  volts * amps
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - JD Warren