eletro 0.0.1
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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/bin/eletro +34 -0
- data/eletro.gemspec +67 -0
- data/lib/eletro/ohm.rb +57 -0
- data/lib/eletro/resistor.rb +127 -0
- data/lib/eletro.rb +16 -0
- data/spec/colour_test +29 -0
- data/spec/eletro/ohm_spec.rb +54 -0
- data/spec/eletro/resistor_spec.rb +147 -0
- data/spec/eletro_spec.rb +7 -0
- data/spec/spec_helper.rb +7 -0
- metadata +112 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Marcos Piccinini
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= eletro
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Note on Patches/Pull Requests
|
6
|
+
|
7
|
+
* Fork the project.
|
8
|
+
* Make your feature addition or bug fix.
|
9
|
+
* Add tests for it. This is important so I don't break it in a
|
10
|
+
future version unintentionally.
|
11
|
+
* Commit, do not mess with rakefile, version, or history.
|
12
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
13
|
+
* Send me a pull request. Bonus points for topic branches.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2010 Marcos Piccinini. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "eletro"
|
8
|
+
gem.summary = %Q{Eletric Helpers on Ruby}
|
9
|
+
gem.description = %Q{Eletric Stuff, Ohm Law, Karnaugh Maps and other gems on Ruby}
|
10
|
+
gem.email = "x@nofxx.com"
|
11
|
+
gem.homepage = "http://github.com/nofxx/eletro"
|
12
|
+
gem.authors = ["Marcos Piccinini"]
|
13
|
+
gem.add_dependency "stick", ">= 1.3.3"
|
14
|
+
gem.add_development_dependency "rspec", ">= 2.0.1"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "eletro #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/eletro
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'optparse'
|
5
|
+
require 'eletro'
|
6
|
+
|
7
|
+
Debug = false
|
8
|
+
|
9
|
+
OptionParser.new { |op|
|
10
|
+
op.on('-d', '--debug') { |d| Debug = true }
|
11
|
+
op.on('-c constants') { |val| set :constants, val.to_sym }
|
12
|
+
}.parse!(ARGV)
|
13
|
+
|
14
|
+
if Debug
|
15
|
+
puts "Starting on #{OS}"
|
16
|
+
end
|
17
|
+
|
18
|
+
if ARGV.empty?
|
19
|
+
puts <<EOF
|
20
|
+
|
21
|
+
|
22
|
+
---------- Eletro!
|
23
|
+
|
24
|
+
Use:
|
25
|
+
|
26
|
+
eletro BKR
|
27
|
+
eletro 220
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
EOF
|
32
|
+
else
|
33
|
+
Eletro.do_your_thing(ARGV)
|
34
|
+
end
|
data/eletro.gemspec
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{eletro}
|
8
|
+
s.version = "0.0.1"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Marcos Piccinini"]
|
12
|
+
s.date = %q{2010-11-10}
|
13
|
+
s.default_executable = %q{eletro}
|
14
|
+
s.description = %q{Eletric Stuff, Ohm Law, Karnaugh Maps and other gems on Ruby}
|
15
|
+
s.email = %q{x@nofxx.com}
|
16
|
+
s.executables = ["eletro"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/eletro",
|
29
|
+
"eletro.gemspec",
|
30
|
+
"lib/eletro.rb",
|
31
|
+
"lib/eletro/ohm.rb",
|
32
|
+
"lib/eletro/resistor.rb",
|
33
|
+
"spec/colour_test",
|
34
|
+
"spec/eletro/ohm_spec.rb",
|
35
|
+
"spec/eletro/resistor_spec.rb",
|
36
|
+
"spec/eletro_spec.rb",
|
37
|
+
"spec/spec_helper.rb"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/nofxx/eletro}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.7}
|
43
|
+
s.summary = %q{Eletric Helpers on Ruby}
|
44
|
+
s.test_files = [
|
45
|
+
"spec/spec_helper.rb",
|
46
|
+
"spec/eletro/ohm_spec.rb",
|
47
|
+
"spec/eletro/resistor_spec.rb",
|
48
|
+
"spec/eletro_spec.rb"
|
49
|
+
]
|
50
|
+
|
51
|
+
if s.respond_to? :specification_version then
|
52
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
53
|
+
s.specification_version = 3
|
54
|
+
|
55
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
|
+
s.add_runtime_dependency(%q<stick>, [">= 1.3.3"])
|
57
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.1"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<stick>, [">= 1.3.3"])
|
60
|
+
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<stick>, [">= 1.3.3"])
|
64
|
+
s.add_dependency(%q<rspec>, [">= 2.0.1"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
data/lib/eletro/ohm.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'stick/units'
|
3
|
+
require 'bigdecimal'
|
4
|
+
|
5
|
+
module Eletro
|
6
|
+
class Ohm
|
7
|
+
attr_accessor :v, :r, :i, :p
|
8
|
+
VALUES = [:v, :r, :i]
|
9
|
+
|
10
|
+
def initialize(*args)
|
11
|
+
args.each { |a| puts a.inspect }
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
# def r
|
16
|
+
# calc(:r) || @r = v / i
|
17
|
+
# end
|
18
|
+
|
19
|
+
def v
|
20
|
+
@v || (calc(:v) ? @v = i * r.to_f : nil)
|
21
|
+
end
|
22
|
+
|
23
|
+
def i
|
24
|
+
@i || (calc(:i) ? @i = v / r.to_f : nil)
|
25
|
+
end
|
26
|
+
|
27
|
+
def r=(r); calc(:r, r); end
|
28
|
+
def v=(v); calc(:v, v); end
|
29
|
+
def i=(i); calc(:i, i); end
|
30
|
+
|
31
|
+
def calc(v, data=nil)
|
32
|
+
if data
|
33
|
+
# instance_variable_set("@#{v}", BigDecimal.new(data.to_s))
|
34
|
+
# puts data.class
|
35
|
+
instance_variable_set("@#{v}", data)
|
36
|
+
else
|
37
|
+
# val = instance_variable_get("@#{v}")
|
38
|
+
# return val if val
|
39
|
+
|
40
|
+
(VALUES - [v]).select { |v| instance_variable_get("@#{v}").nil? }.empty?
|
41
|
+
|
42
|
+
# raise "Can't call dunno #{v}" unless instance_variable_get("@#{v}")
|
43
|
+
# end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
o = ""
|
49
|
+
VALUES.each do |v|
|
50
|
+
if val = send(v)
|
51
|
+
o += "#{val} " + { :r => "Ω", :i => "A", :v => "V"}[v]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
o
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# eletric 220
|
3
|
+
# eletric RRO
|
4
|
+
|
5
|
+
module Eletro
|
6
|
+
|
7
|
+
COLOR = true
|
8
|
+
|
9
|
+
class Resistor
|
10
|
+
attr_reader :value, :color
|
11
|
+
|
12
|
+
UNIT = 'Ω'
|
13
|
+
MULT = /k|m|g/
|
14
|
+
|
15
|
+
CODE = [:k, :b, :r, :o, :y, :g, :u, :v, :a, :w, :l, :s]
|
16
|
+
COLORS = {
|
17
|
+
:k => :black,
|
18
|
+
:b => :brown,
|
19
|
+
:r => :red,
|
20
|
+
:o => :orange,
|
21
|
+
:y => :yellow,
|
22
|
+
:g => :green,
|
23
|
+
:u => :blue,
|
24
|
+
:v => :violet,
|
25
|
+
:a => :gray,
|
26
|
+
:w => :white,
|
27
|
+
:l => :gold,
|
28
|
+
:s => :silver}
|
29
|
+
|
30
|
+
PRECISION = [nil, 1, 2, nil, nil, 0.5, 0.25, 01, 0.05, nil, 5, 10, 20]
|
31
|
+
|
32
|
+
def initialize(*args)
|
33
|
+
params = args.join
|
34
|
+
if params =~ /\d/
|
35
|
+
# m = params.match(/(\d*[,|{k|m|g}|\.]?\d*)\s*(k|m|g)?/)
|
36
|
+
# return unless m
|
37
|
+
@value = parse(params)
|
38
|
+
@color = value2color(@value)
|
39
|
+
else
|
40
|
+
@color = params.split(//)
|
41
|
+
@value = color2value(@color)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def parse txt
|
46
|
+
if mult = txt.match(MULT)
|
47
|
+
txt.gsub!(/#{mult[0]}/, ".") #if txt =~ /#{MULT}\d/
|
48
|
+
mult = { 'k' => 1000, 'm' => 10000000 }[mult[0]]
|
49
|
+
end
|
50
|
+
num = txt.to_f
|
51
|
+
num *= mult if mult
|
52
|
+
num
|
53
|
+
end
|
54
|
+
|
55
|
+
alias :colors :color
|
56
|
+
|
57
|
+
|
58
|
+
def calc char
|
59
|
+
CODE.index(char.downcase.to_sym)
|
60
|
+
end
|
61
|
+
|
62
|
+
def color2value chars
|
63
|
+
out = calc(chars[0])
|
64
|
+
out = (out.to_s + calc(chars[1]).to_s).to_f
|
65
|
+
out *= (10 ** (calc(chars[2])))
|
66
|
+
if chars.size > 3
|
67
|
+
@precision = PRECISION[calc(chars[3])]
|
68
|
+
else
|
69
|
+
#out *= (10 ** (calc(chars[2])))
|
70
|
+
end
|
71
|
+
out
|
72
|
+
end
|
73
|
+
|
74
|
+
def value2color value
|
75
|
+
st, nd, *rest = value.to_s.split(//)
|
76
|
+
out = [CODE[st.to_i], CODE[nd.to_i]]
|
77
|
+
index = 1 if rest.size == 3 # ugly... sleepy... fix....
|
78
|
+
index ||= (value ** 0.1).round
|
79
|
+
out << CODE[index]
|
80
|
+
out.map(&:upcase)
|
81
|
+
end
|
82
|
+
|
83
|
+
def format
|
84
|
+
v = if value < 1000
|
85
|
+
"%g" % @value
|
86
|
+
elsif value < 1000000
|
87
|
+
"%gk" % (@value/1000)
|
88
|
+
else
|
89
|
+
"%gm" % (@value/1000000)
|
90
|
+
end
|
91
|
+
out = "#{v}#{UNIT}"
|
92
|
+
out += " ± #{@precision}%" if @precision
|
93
|
+
out
|
94
|
+
end
|
95
|
+
|
96
|
+
def to_s
|
97
|
+
out = format
|
98
|
+
out += " --"
|
99
|
+
@color.each do |c|
|
100
|
+
out += COLOR ? rgblize(c) : c
|
101
|
+
end
|
102
|
+
out + "--"
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
|
107
|
+
def rgblize color
|
108
|
+
case color.downcase.to_sym
|
109
|
+
when :k then "\e[40m#{color}\e[0m"
|
110
|
+
when :b then "\e[0;33m#{color}\e[0m"
|
111
|
+
when :r then "\e[41m#{color}\e[0m"
|
112
|
+
when :g then "\e[42m#{color}\e[0m"
|
113
|
+
when :y then "\e[1;33m#{color}\e[0m"
|
114
|
+
when :o then "\e[43m#{color}\e[0m"
|
115
|
+
when :u then "\e[44m#{color}\e[0m"
|
116
|
+
when :v then "\e[45m#{color}\e[0m"
|
117
|
+
when :w then "\e[47m#{color}\e[0m"
|
118
|
+
when :a then "\e[31m#{color}\e[0m"
|
119
|
+
else ".."
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
def bold(txt); "\e[2m#{txt}\e[0m"; end
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
data/lib/eletro.rb
ADDED
data/spec/colour_test
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html
|
4
|
+
#
|
5
|
+
# This file echoes a bunch of color codes to the
|
6
|
+
# terminal to demonstrate what's available. Each
|
7
|
+
# line is the color code of one forground color,
|
8
|
+
# out of 17 (default + 16 escapes), followed by a
|
9
|
+
# test use of that color on all nine background
|
10
|
+
# colors (default + 8 escapes).
|
11
|
+
#
|
12
|
+
|
13
|
+
T='gYw' # The test text
|
14
|
+
|
15
|
+
echo -e "\n 40m 41m 42m 43m\
|
16
|
+
44m 45m 46m 47m";
|
17
|
+
|
18
|
+
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
|
19
|
+
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
|
20
|
+
' 36m' '1;36m' ' 37m' '1;37m';
|
21
|
+
do FG=${FGs// /}
|
22
|
+
echo -en " $FGs \033[$FG $T "
|
23
|
+
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
|
24
|
+
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
|
25
|
+
done
|
26
|
+
echo;
|
27
|
+
done
|
28
|
+
echo
|
29
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
|
+
|
4
|
+
describe "Eletro::Ohm" do
|
5
|
+
|
6
|
+
it "should calc ohms law" do
|
7
|
+
o = Ohm.new
|
8
|
+
o.r = 1000
|
9
|
+
o.to_s.should eql("1000 Ω")
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Instance" do
|
13
|
+
let(:o) { Ohm.new }
|
14
|
+
|
15
|
+
it "should set and read attribute" do
|
16
|
+
o.r.should be_nil
|
17
|
+
o.r = 1000
|
18
|
+
o.r.should eql(1000)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should accept stick units [current]" do
|
22
|
+
o.i.should be_nil
|
23
|
+
o.i = 75.mA
|
24
|
+
o.i.to_s.should eql("75 mA")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should accept stick units [volts]" do
|
28
|
+
o.v.should be_nil
|
29
|
+
o.v = 75.V
|
30
|
+
o.v.should eql("75 V")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should calc V if I have [I, R]" do
|
34
|
+
o.i = 0.048
|
35
|
+
o.r = 250
|
36
|
+
o.v.should be_close(12.0, 0.01)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should calc I if I have [V, R]" do
|
40
|
+
o.v = 12
|
41
|
+
o.r = 250
|
42
|
+
o.i.should be_close(0.048, 0.001)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should calc V if I have [I, R]" do
|
46
|
+
o.i = 0.048
|
47
|
+
o.r = 250
|
48
|
+
o.v.should be_close(12.0, 0.01)
|
49
|
+
end
|
50
|
+
# o.r.should eql(1)
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
3
|
+
|
4
|
+
describe "Eletro::Resistor" do
|
5
|
+
|
6
|
+
let(:rs) { Resistor.new }
|
7
|
+
|
8
|
+
describe "Value" do
|
9
|
+
|
10
|
+
it "should instantiate 220 ohms" do
|
11
|
+
r = Resistor.new("220")
|
12
|
+
r.value.should be_close(220.0, 0.1)
|
13
|
+
r.format.should eql("220Ω")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should instantiate 100R ohms" do
|
17
|
+
r = Resistor.new("100R")
|
18
|
+
r.value.should be_close(100.0, 0.1)
|
19
|
+
r.format.should eql("100Ω")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should instantiate 1k ohms" do
|
23
|
+
r = Resistor.new("1k")
|
24
|
+
r.value.should be_close(1000.0, 0.1)
|
25
|
+
r.format.should eql("1kΩ")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should instantiate 1k ohms" do
|
29
|
+
r = Resistor.new("1000.0")
|
30
|
+
r.value.should be_close(1000.0, 0.1)
|
31
|
+
r.format.should eql("1kΩ")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should instantiate 1k ohms" do
|
35
|
+
r = Resistor.new("1100.0")
|
36
|
+
r.value.should be_close(1100.0, 0.1)
|
37
|
+
r.format.should eql("1.1kΩ")
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should instantiate 1k ohms" do
|
41
|
+
r = Resistor.new("BBR")
|
42
|
+
r.value.should be_close(1100.0, 0.1)
|
43
|
+
r.format.should eql("1.1kΩ")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should instantiate 3.3k ohms" do
|
47
|
+
r = Resistor.new("3.3k")
|
48
|
+
r.value.should be_close(3300.0, 0.1)
|
49
|
+
r.format.should eql("3.3kΩ")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should instantiate 4k7 ohms" do
|
53
|
+
r = Resistor.new("4k7")
|
54
|
+
r.value.should be_close(4700.0, 0.1)
|
55
|
+
r.format.should eql("4.7kΩ")
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should instantiate 1m5 ohms" do
|
59
|
+
r = Resistor.new("1m5")
|
60
|
+
r.value.should be_close(15000000.0, 0.01)
|
61
|
+
r.format.should eql("15mΩ")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should get colors for value" do
|
65
|
+
r = Resistor.new("1k")
|
66
|
+
r.colors.join.should eql("BKR")
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should get colors for value" do
|
70
|
+
r = Resistor.new("10k")
|
71
|
+
r.colors.join.should eql("BKO")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should get colors for value" do
|
75
|
+
r = Resistor.new("1.1k")
|
76
|
+
r.colors.join.should eql("BBR")
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should get colors for value" do
|
80
|
+
r = Resistor.new("4k7")
|
81
|
+
r.colors.join.should eql("YVR")
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should get colors for value" do
|
85
|
+
r = Resistor.new("220")
|
86
|
+
r.colors.join.should eql("RRB")
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should get colors for value" do
|
90
|
+
r = Resistor.new("110")
|
91
|
+
r.colors.join.should eql("BBB")
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
describe "Colors" do
|
97
|
+
|
98
|
+
it "should instantiate 3 chars" do
|
99
|
+
r = Resistor.new("BKR")
|
100
|
+
r.value.should be_close(1000.0, 0.01)
|
101
|
+
r.format.should eql("1kΩ")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should instantiate 3 chars" do
|
105
|
+
r = Resistor.new("BKO")
|
106
|
+
r.value.should be_close(10000.0, 0.01)
|
107
|
+
r.format.should eql("10kΩ")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should instantiate 3 chars" do
|
111
|
+
r = Resistor.new("YVR")
|
112
|
+
r.value.should be_close(4700.0, 0.01)
|
113
|
+
r.format.should eql("4.7kΩ")
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should instantiate 3 chars" do
|
117
|
+
r = Resistor.new("YVR")
|
118
|
+
r.value.should be_close(4700.0, 0.01)
|
119
|
+
r.format.should eql("4.7kΩ")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should instantiate 4 chars" do
|
123
|
+
r = Resistor.new("WWRS")
|
124
|
+
r.value.should be_close(9900.0, 0.01)
|
125
|
+
r.format.should eql("9.9kΩ ± 10%")
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should instantiate 4 chars" do
|
129
|
+
r = Resistor.new("BKRL")
|
130
|
+
r.value.should be_close(1000.0, 0.01)
|
131
|
+
r.format.should eql("1kΩ ± 5%")
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
|
137
|
+
describe "Colors" do
|
138
|
+
|
139
|
+
it "should print nicely" do
|
140
|
+
r = Resistor.new("BKR")
|
141
|
+
r.value.should be_close(1000.0, 0.01)
|
142
|
+
r.to_s.should eql("1kΩ --\e[0;33mB\e[0m\e[40mK\e[0m\e[41mR\e[0m--")
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
data/spec/eletro_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eletro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Marcos Piccinini
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-11-10 00:00:00 -02:00
|
18
|
+
default_executable: eletro
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: stick
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 3
|
31
|
+
- 3
|
32
|
+
version: 1.3.3
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 0
|
46
|
+
- 1
|
47
|
+
version: 2.0.1
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
description: Eletric Stuff, Ohm Law, Karnaugh Maps and other gems on Ruby
|
51
|
+
email: x@nofxx.com
|
52
|
+
executables:
|
53
|
+
- eletro
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files:
|
57
|
+
- LICENSE
|
58
|
+
- README.rdoc
|
59
|
+
files:
|
60
|
+
- .document
|
61
|
+
- .gitignore
|
62
|
+
- LICENSE
|
63
|
+
- README.rdoc
|
64
|
+
- Rakefile
|
65
|
+
- VERSION
|
66
|
+
- bin/eletro
|
67
|
+
- eletro.gemspec
|
68
|
+
- lib/eletro.rb
|
69
|
+
- lib/eletro/ohm.rb
|
70
|
+
- lib/eletro/resistor.rb
|
71
|
+
- spec/colour_test
|
72
|
+
- spec/eletro/ohm_spec.rb
|
73
|
+
- spec/eletro/resistor_spec.rb
|
74
|
+
- spec/eletro_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
has_rdoc: true
|
77
|
+
homepage: http://github.com/nofxx/eletro
|
78
|
+
licenses: []
|
79
|
+
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options:
|
82
|
+
- --charset=UTF-8
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
requirements: []
|
102
|
+
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 1.3.7
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: Eletric Helpers on Ruby
|
108
|
+
test_files:
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
- spec/eletro/ohm_spec.rb
|
111
|
+
- spec/eletro/resistor_spec.rb
|
112
|
+
- spec/eletro_spec.rb
|