resistor 0.1.0 → 0.2.0
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 +9 -0
- data/lib/resistor/basic_resistor.rb +22 -0
- data/lib/resistor/color_code.rb +24 -0
- data/lib/resistor/version.rb +1 -1
- data/resistor.gemspec +1 -1
- data/spec/basic_resistor_spec.rb +32 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1843455385e168419277b5628bade0ecafb8005
|
4
|
+
data.tar.gz: 0aa86e44feaf9e0e95f1e7612dd40dd1d95b9959
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ebb48ab4c70a33a07256c8832499ac1ac2b9236e0c0d6f6d85dceb19a087a6b271c4d7c5662f9de34b68403921e46e5acb4ffe447db88574535c3211d6d47f0
|
7
|
+
data.tar.gz: edd66c46793afb5b9c9553e360377ecb9d81befafca2dabe5e6cb697450c69e4966c9ba1dea4edf8751082dcf3a8ebfbd2b2e155503c29a328327dee82a91b2b
|
data/README.md
CHANGED
@@ -37,4 +37,13 @@ r4 = Resistor.new(ohm: 8)
|
|
37
37
|
|
38
38
|
r5 = (r1 / r2) + r3 + (r4 / r4)
|
39
39
|
r5.ohm # => 20.0
|
40
|
+
|
41
|
+
# E Series Checker
|
42
|
+
r1 = Resistor.new(ohm: 4700)
|
43
|
+
r2 = Resistor.new(ohm: 62)
|
44
|
+
|
45
|
+
r1.e12? # => true
|
46
|
+
r1.e24? # => true
|
47
|
+
r2.e12? # => false
|
48
|
+
r2.e24? # => true
|
40
49
|
```
|
@@ -37,5 +37,27 @@ module Resistor
|
|
37
37
|
def /(other)
|
38
38
|
Resistor::CombinedResistor.new(1 / (1 / @ohm + 1 / other.ohm))
|
39
39
|
end
|
40
|
+
|
41
|
+
def e12?
|
42
|
+
num0 = Resistor::ColorCode::NUM[@code[0]]
|
43
|
+
num1 = Resistor::ColorCode::NUM[@code[1]]
|
44
|
+
Resistor::ColorCode::E12_SERIES.each do |key, val|
|
45
|
+
if num0 == key
|
46
|
+
return true if val.any? { |e| e == num1 }
|
47
|
+
end
|
48
|
+
end
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
|
52
|
+
def e24?
|
53
|
+
num0 = Resistor::ColorCode::NUM[@code[0]]
|
54
|
+
num1 = Resistor::ColorCode::NUM[@code[1]]
|
55
|
+
Resistor::ColorCode::E24_SERIES.each do |key, val|
|
56
|
+
if num0 == key
|
57
|
+
return true if val.any? { |e| e == num1 }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
return false
|
61
|
+
end
|
40
62
|
end
|
41
63
|
end
|
data/lib/resistor/color_code.rb
CHANGED
@@ -40,6 +40,30 @@ module Resistor
|
|
40
40
|
:silver => 10.0
|
41
41
|
}.freeze
|
42
42
|
|
43
|
+
# E12系列
|
44
|
+
E12_SERIES = {
|
45
|
+
1 => [0, 2, 5, 8],
|
46
|
+
2 => [2, 7],
|
47
|
+
3 => [3, 9],
|
48
|
+
4 => [7],
|
49
|
+
5 => [6],
|
50
|
+
6 => [8],
|
51
|
+
8 => [2],
|
52
|
+
}.freeze
|
53
|
+
|
54
|
+
# E24系列
|
55
|
+
E24_SERIES = {
|
56
|
+
1 => [0, 1, 2, 3, 5, 6, 8],
|
57
|
+
2 => [0, 2, 4, 7],
|
58
|
+
3 => [0, 3, 6, 9],
|
59
|
+
4 => [3, 7],
|
60
|
+
5 => [1, 6],
|
61
|
+
6 => [2, 8],
|
62
|
+
7 => [5],
|
63
|
+
8 => [2],
|
64
|
+
9 => [1]
|
65
|
+
}.freeze
|
66
|
+
|
43
67
|
# 抵抗値 -> カラーコード
|
44
68
|
def self.encode(ohm, error_range: 5.0)
|
45
69
|
return [NUM.key(0)] if ohm == 0
|
data/lib/resistor/version.rb
CHANGED
data/resistor.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["seinosuke.3606@gmail.com"]
|
11
11
|
spec.summary = %q{Resistor gem}
|
12
12
|
spec.description = %q{gem for resistor}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/seinosuke/resistor"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
data/spec/basic_resistor_spec.rb
CHANGED
@@ -78,4 +78,36 @@ describe Resistor::BasicResistor do
|
|
78
78
|
it { expect(resistor.error_range).to eq 1.0 }
|
79
79
|
end
|
80
80
|
end
|
81
|
+
|
82
|
+
describe '#e12?' do
|
83
|
+
context 'E12系列である場合' do
|
84
|
+
it { expect(Resistor.new(ohm: 0.12).e12?).to eq true }
|
85
|
+
it { expect(Resistor.new(ohm: 3.3).e12?).to eq true }
|
86
|
+
it { expect(Resistor.new(ohm: 47).e12?).to eq true }
|
87
|
+
it { expect(Resistor.new(ohm: 82_000_000).e12?).to eq true }
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'E12系列でない場合' do
|
91
|
+
it { expect(Resistor.new(ohm: 0.13).e12?).to eq false }
|
92
|
+
it { expect(Resistor.new(ohm: 3.8).e12?).to eq false }
|
93
|
+
it { expect(Resistor.new(ohm: 55).e12?).to eq false }
|
94
|
+
it { expect(Resistor.new(ohm: 70_000_000).e12?).to eq false }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#e24?' do
|
99
|
+
context 'E24系列である場合' do
|
100
|
+
it { expect(Resistor.new(ohm: 0.1).e24?).to eq true }
|
101
|
+
it { expect(Resistor.new(ohm: 3).e24?).to eq true }
|
102
|
+
it { expect(Resistor.new(ohm: 47_000).e24?).to eq true }
|
103
|
+
it { expect(Resistor.new(ohm: 10_000_000).e24?).to eq true }
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'E24系列でない場合' do
|
107
|
+
it { expect(Resistor.new(ohm: 0.92).e24?).to eq false }
|
108
|
+
it { expect(Resistor.new(ohm: 8.3).e24?).to eq false }
|
109
|
+
it { expect(Resistor.new(ohm: 23_000).e24?).to eq false }
|
110
|
+
it { expect(Resistor.new(ohm: 52_000_000).e24?).to eq false }
|
111
|
+
end
|
112
|
+
end
|
81
113
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resistor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- seinosuke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -74,7 +74,7 @@ files:
|
|
74
74
|
- spec/basic_resistor_spec.rb
|
75
75
|
- spec/color_code_spec.rb
|
76
76
|
- spec/spec_helper.rb
|
77
|
-
homepage:
|
77
|
+
homepage: https://github.com/seinosuke/resistor
|
78
78
|
licenses:
|
79
79
|
- MIT
|
80
80
|
metadata: {}
|