necromancer 0.3.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +70 -3
  3. data/README.md +204 -86
  4. data/lib/necromancer.rb +17 -18
  5. data/lib/necromancer/configuration.rb +1 -1
  6. data/lib/necromancer/context.rb +16 -3
  7. data/lib/necromancer/conversion_target.rb +31 -14
  8. data/lib/necromancer/conversions.rb +39 -16
  9. data/lib/necromancer/converter.rb +10 -8
  10. data/lib/necromancer/converters/array.rb +143 -45
  11. data/lib/necromancer/converters/boolean.rb +21 -19
  12. data/lib/necromancer/converters/date_time.rb +58 -13
  13. data/lib/necromancer/converters/hash.rb +119 -0
  14. data/lib/necromancer/converters/numeric.rb +32 -28
  15. data/lib/necromancer/converters/range.rb +44 -18
  16. data/lib/necromancer/null_converter.rb +4 -2
  17. data/lib/necromancer/version.rb +2 -2
  18. metadata +39 -72
  19. data/.gitignore +0 -14
  20. data/.rspec +0 -3
  21. data/.ruby-version +0 -1
  22. data/.travis.yml +0 -19
  23. data/Gemfile +0 -16
  24. data/Rakefile +0 -8
  25. data/necromancer.gemspec +0 -21
  26. data/spec/spec_helper.rb +0 -53
  27. data/spec/unit/can_spec.rb +0 -11
  28. data/spec/unit/config_spec.rb +0 -32
  29. data/spec/unit/configuration/new_spec.rb +0 -30
  30. data/spec/unit/conversions/register_spec.rb +0 -49
  31. data/spec/unit/convert_spec.rb +0 -104
  32. data/spec/unit/converters/array/array_to_boolean_spec.rb +0 -22
  33. data/spec/unit/converters/array/array_to_numeric_spec.rb +0 -22
  34. data/spec/unit/converters/array/array_to_set_spec.rb +0 -18
  35. data/spec/unit/converters/array/object_to_array_spec.rb +0 -21
  36. data/spec/unit/converters/array/string_to_array_spec.rb +0 -33
  37. data/spec/unit/converters/boolean/boolean_to_integer_spec.rb +0 -26
  38. data/spec/unit/converters/boolean/integer_to_boolean_spec.rb +0 -22
  39. data/spec/unit/converters/boolean/string_to_boolean_spec.rb +0 -36
  40. data/spec/unit/converters/date_time/string_to_date_spec.rb +0 -22
  41. data/spec/unit/converters/date_time/string_to_datetime_spec.rb +0 -32
  42. data/spec/unit/converters/numeric/string_to_float_spec.rb +0 -48
  43. data/spec/unit/converters/numeric/string_to_integer_spec.rb +0 -62
  44. data/spec/unit/converters/numeric/string_to_numeric_spec.rb +0 -32
  45. data/spec/unit/converters/range/string_to_range_spec.rb +0 -35
  46. data/spec/unit/new_spec.rb +0 -12
  47. data/spec/unit/register_spec.rb +0 -17
  48. data/tasks/console.rake +0 -10
  49. data/tasks/coverage.rake +0 -11
  50. data/tasks/spec.rake +0 -29
@@ -1,32 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Necromancer::NumericConverters::StringToNumericConverter, '.call' do
6
-
7
- subject(:converter) { described_class.new(:string, :numeric) }
8
-
9
- {
10
- '1' => 1,
11
- '+1' => 1,
12
- '-1' => -1,
13
- '1e1' => 10.0,
14
- '1e-1' => 0.1,
15
- '-1e1' => -10.0,
16
- '-1e-1' => -0.1,
17
- '1.0' => 1.0,
18
- '1.0e+1' => 10.0,
19
- '1.0e-1' => 0.1,
20
- '-1.0e+1' => -10.0,
21
- '-1.0e-1' => -0.1,
22
- '.1' => 0.1,
23
- '.1e+1' => 1.0,
24
- '.1e-1' => 0.01,
25
- '-.1e+1' => -1.0,
26
- '-.1e-1' => -0.01
27
- }.each do |actual, expected|
28
- it "converts '#{actual}' to '#{expected}'" do
29
- expect(converter.call(actual)).to eql(expected)
30
- end
31
- end
32
- end
@@ -1,35 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Necromancer::RangeConverters::StringToRangeConverter, '.call' do
6
-
7
- subject(:converter) { described_class.new }
8
-
9
- it "raises error for empty string in strict mode" do
10
- expect {
11
- converter.call('', strict: true)
12
- }.to raise_error(Necromancer::ConversionTypeError)
13
- end
14
-
15
- it "returns value in non-strict mode" do
16
- expect(converter.call('', strict: false)).to eq('')
17
- end
18
-
19
- {
20
- '1' => 1..1,
21
- '1..10' => 1..10,
22
- '1-10' => 1..10,
23
- '1,10' => 1..10,
24
- '1...10' => 1...10,
25
- '-1..10' => -1..10,
26
- '1..-10' => 1..-10,
27
- 'a..z' => 'a'..'z',
28
- 'a-z' => 'a'..'z',
29
- 'A-Z' => 'A'..'Z'
30
- }.each do |actual, expected|
31
- it "converts '#{actual}' to range type" do
32
- expect(converter.call(actual)).to eql(expected)
33
- end
34
- end
35
- end
@@ -1,12 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Necromancer, '#new' do
6
-
7
- subject(:converter) { described_class.new }
8
-
9
- it "creates context" do
10
- expect(converter).to be_a(Necromancer::Context)
11
- end
12
- end
@@ -1,17 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Necromancer, '.register' do
6
- it "allows ro register converter" do
7
- converter = described_class.new
8
- UpcaseConverter = Struct.new(:source, :target) do
9
- def call(value, options)
10
- value.to_s.upcase
11
- end
12
- end
13
- upcase_converter = UpcaseConverter.new(:string, :upcase)
14
- expect(converter.register(upcase_converter)).to eq(true)
15
- expect(converter.convert('magic').to(:upcase)).to eq('MAGIC')
16
- end
17
- end
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Load gem inside irb console'
4
- task :console do
5
- require 'irb'
6
- require 'irb/completion'
7
- require File.join(__FILE__, '../../lib/necromancer')
8
- ARGV.clear
9
- IRB.start
10
- end
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Measure code coverage'
4
- task :coverage do
5
- begin
6
- original, ENV['COVERAGE'] = ENV['COVERAGE'], 'true'
7
- Rake::Task['spec'].invoke
8
- ensure
9
- ENV['COVERAGE'] = original
10
- end
11
- end
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- begin
4
- require 'rspec/core/rake_task'
5
-
6
- desc 'Run all specs'
7
- RSpec::Core::RakeTask.new(:spec) do |task|
8
- task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
9
- end
10
-
11
- namespace :spec do
12
- desc 'Run unit specs'
13
- RSpec::Core::RakeTask.new(:unit) do |task|
14
- task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
15
- end
16
-
17
- desc 'Run integration specs'
18
- RSpec::Core::RakeTask.new(:integration) do |task|
19
- task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
20
- end
21
- end
22
-
23
- rescue LoadError
24
- %w[spec spec:unit spec:integration].each do |name|
25
- task name do
26
- $stderr.puts "In order to run #{name}, do `gem install rspec`"
27
- end
28
- end
29
- end