valuer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/main.yml +18 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +22 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +55 -0
- data/LICENSE.txt +21 -0
- data/README.md +27 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/valuer/version.rb +5 -0
- data/lib/valuer.rb +47 -0
- data/valuer.gemspec +32 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 267032c2120493c729b261d5a1451a01a5e197665b4d6df043440a3fed8c1083
|
4
|
+
data.tar.gz: 345e7cebe54cde5eca7f1441900f3aaa945e3587b61ecd5d3f3371bd91d2a7a9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cee18542dea6ca94dad588c1fc9e1fb8d3aef4ab0a8b67157449f20d43cfb85f8d39380c338c5d6ef351aae1d95f3729b9b32744a59735979a1e7fdee0cc3bd5
|
7
|
+
data.tar.gz: 9565d6869b87201571a2423a2040776184d7c17fb204c26c88487d0f2f323151c1cf020be7e3cd055d253a947b2416fbe1b329c43cbb2a7b87e6fc72fd667aa1
|
@@ -0,0 +1,18 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on: [push,pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- uses: actions/checkout@v2
|
10
|
+
- name: Set up Ruby
|
11
|
+
uses: ruby/setup-ruby@v1
|
12
|
+
with:
|
13
|
+
ruby-version: 3.0.0
|
14
|
+
- name: Run the default task
|
15
|
+
run: |
|
16
|
+
gem install bundler -v 2.2.3
|
17
|
+
bundle install
|
18
|
+
bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Style/StringLiterals:
|
2
|
+
Enabled: true
|
3
|
+
EnforcedStyle: double_quotes
|
4
|
+
|
5
|
+
Style/StringLiteralsInInterpolation:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Layout/LineLength:
|
10
|
+
Max: 120
|
11
|
+
|
12
|
+
AllCops:
|
13
|
+
NewCops: enable
|
14
|
+
|
15
|
+
Metrics/CyclomaticComplexity:
|
16
|
+
Enabled: false
|
17
|
+
Metrics/AbcSize:
|
18
|
+
Enabled: false
|
19
|
+
Metrics/MethodLength:
|
20
|
+
Enabled: false
|
21
|
+
Metrics/PerceivedComplexity:
|
22
|
+
Enabled: false
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
valuer (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
parallel (1.20.1)
|
12
|
+
parser (3.0.2.0)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.0.0)
|
15
|
+
rake (13.0.6)
|
16
|
+
regexp_parser (2.1.1)
|
17
|
+
rexml (3.2.5)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.1)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.1)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.2)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.2)
|
31
|
+
rubocop (0.93.1)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.7.1.5)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8)
|
36
|
+
rexml
|
37
|
+
rubocop-ast (>= 0.6.0)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
40
|
+
rubocop-ast (1.11.0)
|
41
|
+
parser (>= 3.0.1.1)
|
42
|
+
ruby-progressbar (1.11.0)
|
43
|
+
unicode-display_width (1.7.0)
|
44
|
+
|
45
|
+
PLATFORMS
|
46
|
+
x86_64-darwin-20
|
47
|
+
|
48
|
+
DEPENDENCIES
|
49
|
+
rake (~> 13.0)
|
50
|
+
rspec (~> 3.0)
|
51
|
+
rubocop (~> 0.80)
|
52
|
+
valuer!
|
53
|
+
|
54
|
+
BUNDLED WITH
|
55
|
+
2.2.3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Matti Paksula
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Valuer
|
2
|
+
|
3
|
+
require "valuer"
|
4
|
+
|
5
|
+
Valuer.value Integer, "20"
|
6
|
+
=> 20
|
7
|
+
|
8
|
+
Valuer.value Integer, "20x"
|
9
|
+
=> Valuer::Error (invalid value for Integer(): "20x")
|
10
|
+
|
11
|
+
Valuer.value Integer, "20x", default: -1
|
12
|
+
=> -1
|
13
|
+
|
14
|
+
Valuer.value Integer, "20", min: 21
|
15
|
+
=> Valuer::MinimumError (minimum is 21)
|
16
|
+
|
17
|
+
Valuer.value Integer, "20", min: 19
|
18
|
+
=> Valuer::MaximumError (maximum is 19)
|
19
|
+
|
20
|
+
Valuer.value Float, "1.2", min: 1, max: 20
|
21
|
+
=> 1.2
|
22
|
+
|
23
|
+
Valuer.value TrueClass, "yes"
|
24
|
+
=> true
|
25
|
+
|
26
|
+
Valuer.value TrueClass, "no"
|
27
|
+
=> false
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "valuer"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/valuer.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "valuer/version"
|
4
|
+
|
5
|
+
# a person whose job is to estimate the value of something that is to be purchased.
|
6
|
+
module Valuer
|
7
|
+
class Error < StandardError; end
|
8
|
+
|
9
|
+
class MinimumError < StandardError; end
|
10
|
+
|
11
|
+
class MaximumError < StandardError; end
|
12
|
+
|
13
|
+
def self.value(type, value, opts = {})
|
14
|
+
result = nil
|
15
|
+
begin
|
16
|
+
result = case type.name
|
17
|
+
when "Integer"
|
18
|
+
Integer value
|
19
|
+
when "Float"
|
20
|
+
Float value
|
21
|
+
when "TrueClass"
|
22
|
+
case value
|
23
|
+
when "yes"
|
24
|
+
true
|
25
|
+
else
|
26
|
+
value == true
|
27
|
+
end
|
28
|
+
when "FalseClass"
|
29
|
+
case value
|
30
|
+
when "no"
|
31
|
+
true
|
32
|
+
else
|
33
|
+
value == true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
rescue StandardError => e
|
37
|
+
return opts[:default] if opts[:default]
|
38
|
+
|
39
|
+
raise Valuer::Error, e.to_s
|
40
|
+
end
|
41
|
+
|
42
|
+
raise Valuer::MinimumError, "minimum is #{opts[:min]}" if opts[:min] && result < opts[:min]
|
43
|
+
raise Valuer::MaximumError, "maximum is #{opts[:max]}" if opts[:max] && result > opts[:max]
|
44
|
+
|
45
|
+
result
|
46
|
+
end
|
47
|
+
end
|
data/valuer.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/valuer/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "valuer"
|
7
|
+
spec.version = Valuer::VERSION
|
8
|
+
spec.authors = ["Matti Paksula"]
|
9
|
+
spec.email = ["matti.paksula@iki.fi"]
|
10
|
+
|
11
|
+
spec.summary = "a person whose job is to estimate the value of something that is to be purchased."
|
12
|
+
spec.homepage = "https://github.com/matti/valuer-ruby"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
# Uncomment to register a new dependency of your gem
|
28
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
29
|
+
|
30
|
+
# For more information and examples about making a new gem, checkout our
|
31
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: valuer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matti Paksula
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-01 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- matti.paksula@iki.fi
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".github/workflows/main.yml"
|
21
|
+
- ".gitignore"
|
22
|
+
- ".rspec"
|
23
|
+
- ".rubocop.yml"
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE.txt
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/setup
|
31
|
+
- lib/valuer.rb
|
32
|
+
- lib/valuer/version.rb
|
33
|
+
- valuer.gemspec
|
34
|
+
homepage: https://github.com/matti/valuer-ruby
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata:
|
38
|
+
homepage_uri: https://github.com/matti/valuer-ruby
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.5.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.2.3
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: a person whose job is to estimate the value of something that is to be purchased.
|
58
|
+
test_files: []
|