sparkie 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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sparkie.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jon Gold
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Sparkie
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'sparkie'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sparkie
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,3 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new('spec')
@@ -0,0 +1,49 @@
1
+ require "sparkie/version"
2
+
3
+ module Sparkie
4
+ def self.version_string
5
+ "Sparkie version #{Sparkie::VERSION}"
6
+ end
7
+
8
+ class Resistor
9
+ COLORS = {
10
+ '-2' => {name: 'silver', multiplier: '0.01'},
11
+ '-1' => {name: 'gold', multiplier: '0.1'},
12
+ '0' => {name: 'black', figure: '0', multiplier: '1'},
13
+ '1' => {name: 'brown', figure: '1', multiplier: '10'},
14
+ '2' => {name: 'red', figure: '2', multiplier: '100'},
15
+ '3' => {name: 'orange', figure: '3', multiplier: '1K'},
16
+ '4' => {name: 'yellow', figure: '4', multiplier: '10K'},
17
+ '5' => {name: 'green', figure: '5', multiplier: '100K'},
18
+ '6' => {name: 'blue', figure: '6', multiplier: '1M'},
19
+ '7' => {name: 'purple', figure: '7', multiplier: '10M'},
20
+ '8' => {name: 'gray', figure: '8', multiplier: '100M'},
21
+ '9' => {name: 'white', figure: '9', multiplier: '1000M'}
22
+ }
23
+
24
+ def self.from_colors(colors)
25
+ case colors.length
26
+ when 4
27
+ num_1 = colors[0]
28
+ num_2 = colors[1]
29
+ multiplier = colors[2]
30
+ tolerance = colors[3]
31
+
32
+ (COLORS[num_1.to_s][:figure] + COLORS[num_2.to_s][:figure]).to_i * multiplier(COLORS[multiplier.to_s][:multiplier])
33
+ when 5
34
+ num_1 = colors[0]
35
+ num_2 = colors[1]
36
+ num_3 = colors[2]
37
+ multiplier = colors[3]
38
+ tolerance = colors[4]
39
+ (COLORS[num_1.to_s][:figure] + COLORS[num_2.to_s][:figure] + COLORS[num_3.to_s][:figure]).to_i * multiplier(COLORS[multiplier.to_s][:multiplier])
40
+ else
41
+ raise(ArgumentError, 'only 4 or 5 colors please!')
42
+ end
43
+ end
44
+
45
+ def self.multiplier(num)
46
+ num.gsub(/K/, '000').gsub(/M/, '000_000').to_i
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Sparkie
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sparkie/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sparkie"
8
+ spec.version = Sparkie::VERSION
9
+ spec.authors = ["Jon Gold"]
10
+ spec.email = ["hello@designedbygold.com"]
11
+ spec.description = %q{Tools for working with electronics}
12
+ spec.summary = %q{Tools for working with electronics with Ruby}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Sparkie do
4
+ it 'returns the correct version number' do
5
+ expect(Sparkie.version_string).to eq "Sparkie version #{Sparkie::VERSION}"
6
+ end
7
+
8
+ describe Sparkie::Resistor do
9
+ it 'creates a new resistor object' do
10
+ expect(Sparkie::Resistor.new).to be_a Sparkie::Resistor
11
+ end
12
+
13
+ describe "colors" do
14
+ it 'has a dictionary of values' do
15
+ expect( Sparkie::Resistor::COLORS ).to be_a Hash
16
+
17
+ 9.times do |i|
18
+ expect( Sparkie::Resistor::COLORS[i.to_s][:name] ).to be_a String
19
+ expect( Sparkie::Resistor::COLORS[i.to_s][:figure] ).to be_a String
20
+ expect( Sparkie::Resistor::COLORS[i.to_s][:multiplier] ).to be_a String
21
+ end
22
+ end
23
+ end
24
+
25
+ describe '::from_colors'
26
+ it 'responds to ::from_colors' do
27
+ expect( Sparkie::Resistor ).to respond_to :from_colors
28
+ end
29
+
30
+ it 'needs an array of colors' do
31
+ expect { Sparkie::Resistor::from_colors }.to raise_error(ArgumentError)
32
+ expect { Sparkie::Resistor::from_colors([1, 2, 3, 4]) }.to_not raise_error(ArgumentError)
33
+ end
34
+
35
+ it 'only accepts 4 or 5 colors' do
36
+ expect { Sparkie::Resistor::from_colors([1, 2, 3]) }.to raise_error(ArgumentError)
37
+ expect { Sparkie::Resistor::from_colors([1, 2, 3, 4]) }.to_not raise_error(ArgumentError)
38
+ expect { Sparkie::Resistor::from_colors([1, 2, 3, 4, 5]) }.to_not raise_error(ArgumentError)
39
+ expect { Sparkie::Resistor::from_colors([1, 2, 3, 4, 5, 6]) }.to raise_error(ArgumentError)
40
+ end
41
+
42
+ describe 'with valid attributes!' do
43
+ it 'returns a number' do
44
+ expect( Sparkie::Resistor::from_colors([1, 2, 3, 4]) ).to be_an Integer
45
+ end
46
+
47
+ it 'converts references to Ohms' do
48
+ expect( Sparkie::Resistor::from_colors([2, 2, 1, 1]) ).to eq 220
49
+ expect( Sparkie::Resistor::from_colors([1, 0, 2, 1]) ).to eq 1000
50
+ expect( Sparkie::Resistor::from_colors([1, 0, 3, 1]) ).to eq 10000
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'sparkie'
3
+
4
+ RSpec.configure do |config|
5
+ config.color_enabled = true
6
+ config.formatter = 'documentation'
7
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sparkie
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jon Gold
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Tools for working with electronics
63
+ email:
64
+ - hello@designedbygold.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - lib/sparkie.rb
75
+ - lib/sparkie/version.rb
76
+ - sparkie.gemspec
77
+ - spec/sparkie_spec.rb
78
+ - spec/spec_helper.rb
79
+ homepage: ''
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.23
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Tools for working with electronics with Ruby
104
+ test_files:
105
+ - spec/sparkie_spec.rb
106
+ - spec/spec_helper.rb
107
+ has_rdoc: