strom 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +8 -0
- data/lib/strom.rb +6 -0
- data/lib/strom/numeric.rb +13 -0
- data/lib/strom/variable.rb +33 -0
- data/lib/strom/version.rb +3 -0
- data/strom.gemspec +24 -0
- data/test/numeric_test.rb +24 -0
- data/test/test_helper.rb +2 -0
- data/test/variable_test.rb +20 -0
- metadata +103 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5d61b39f0744381d320e9f4f2235f91dbca055e5
|
4
|
+
data.tar.gz: db87b24c86db4c2ea37db6f97dba486607021046
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2f49bc2307e4e68c5f9936b44ce3f22f727d644ad9a42903922b5450701b5b35e0059cdc392959dedff2b065c577593df86f9588b175fd27aa7431866158c789
|
7
|
+
data.tar.gz: 0837348cb5a3f04df5d616a6f6d836f697592b37ea297bb6f0086c93b5449c24f00fbf6ad5dd456655133608f0c30e2f2e05ff551e66057561fec39f676b5953
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 David Boot
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/kodnin/strom.svg?branch=master)](https://travis-ci.org/kodnin/strom)
|
2
|
+
|
3
|
+
# Strom
|
4
|
+
|
5
|
+
Ohm's law expressed in Ruby.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'strom'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install strom
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Require the gem in your project or ```irb``` and find the unknown element:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'strom'
|
29
|
+
# => true
|
30
|
+
0.5.amperes.and(18.ohms)
|
31
|
+
# => 9.0 volts
|
32
|
+
18.ohms.and(9.volts)
|
33
|
+
# => 0.5 amperes
|
34
|
+
9.volts.and(0.5.amperes)
|
35
|
+
# => 18.0 ohms
|
36
|
+
```
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/kodnin/strom/fork )
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/strom.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
class Variable < Struct.new(:value)
|
2
|
+
def and(other)
|
3
|
+
current = resistance = voltage = nil
|
4
|
+
|
5
|
+
[self, other].each do |element|
|
6
|
+
case element
|
7
|
+
when Ampere
|
8
|
+
current = element.value
|
9
|
+
when Ohm
|
10
|
+
resistance = element.value
|
11
|
+
when Volt
|
12
|
+
voltage = element.value
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if current.nil?
|
17
|
+
Ampere.new(voltage / resistance)
|
18
|
+
elsif resistance.nil?
|
19
|
+
Ohm.new(voltage / current)
|
20
|
+
elsif voltage.nil?
|
21
|
+
Volt.new(current * resistance)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Ampere < Variable
|
27
|
+
end
|
28
|
+
|
29
|
+
class Ohm < Variable
|
30
|
+
end
|
31
|
+
|
32
|
+
class Volt < Variable
|
33
|
+
end
|
data/strom.gemspec
ADDED
@@ -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 'strom/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'strom'
|
8
|
+
spec.version = Strom::VERSION
|
9
|
+
spec.authors = ['David Boot']
|
10
|
+
spec.email = ['kodnin@gmail.com']
|
11
|
+
spec.summary = "Ohm's law."
|
12
|
+
spec.description = "Ohm's law expressed in Ruby."
|
13
|
+
spec.homepage = 'https://github.com/kodnin/strom'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'minitest', '~> 5.4.3'
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative './test_helper'
|
2
|
+
|
3
|
+
describe Numeric do
|
4
|
+
it '#amperes' do
|
5
|
+
a = 0.5.amperes
|
6
|
+
a.must_be_kind_of Struct
|
7
|
+
a.must_be_instance_of Ampere
|
8
|
+
a.must_equal Ampere.new(0.5)
|
9
|
+
end
|
10
|
+
|
11
|
+
it '#ohms' do
|
12
|
+
o = 18.ohms
|
13
|
+
o.must_be_kind_of Struct
|
14
|
+
o.must_be_instance_of Ohm
|
15
|
+
o.must_equal Ohm.new(18.0)
|
16
|
+
end
|
17
|
+
|
18
|
+
it '#volts' do
|
19
|
+
v = 9.volts
|
20
|
+
v.must_be_kind_of Struct
|
21
|
+
v.must_be_instance_of Volt
|
22
|
+
v.must_equal Volt.new(9.0)
|
23
|
+
end
|
24
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative './test_helper'
|
2
|
+
|
3
|
+
describe Variable do
|
4
|
+
before { @variable = Variable.new(1.0) }
|
5
|
+
|
6
|
+
it '#initialize' do
|
7
|
+
@variable.must_be_kind_of Struct
|
8
|
+
@variable.must_be_instance_of Variable
|
9
|
+
end
|
10
|
+
|
11
|
+
it '#value' do
|
12
|
+
@variable.value.must_equal 1.0
|
13
|
+
end
|
14
|
+
|
15
|
+
it '#and' do
|
16
|
+
0.5.amperes.and(18.ohms).must_equal Volt.new(9.0)
|
17
|
+
18.ohms.and(9.volts).must_equal Ampere.new(0.5)
|
18
|
+
9.volts.and(0.5.amperes).must_equal Ohm.new(18.0)
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Boot
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.4.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.4.3
|
55
|
+
description: Ohm's law expressed in Ruby.
|
56
|
+
email:
|
57
|
+
- kodnin@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/strom.rb
|
69
|
+
- lib/strom/numeric.rb
|
70
|
+
- lib/strom/variable.rb
|
71
|
+
- lib/strom/version.rb
|
72
|
+
- strom.gemspec
|
73
|
+
- test/numeric_test.rb
|
74
|
+
- test/test_helper.rb
|
75
|
+
- test/variable_test.rb
|
76
|
+
homepage: https://github.com/kodnin/strom
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.4
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Ohm's law.
|
100
|
+
test_files:
|
101
|
+
- test/numeric_test.rb
|
102
|
+
- test/test_helper.rb
|
103
|
+
- test/variable_test.rb
|