transproc 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 191351a547ec40a988d4948a669c8a19a9d9e7b5
4
- data.tar.gz: 6fa7367728d8b2738b0cb8385bb5f95711952530
3
+ metadata.gz: 87334e10cb8bf6cccb2f48272486e54ad024260f
4
+ data.tar.gz: 58910ac82cf4b9b73567e8fe548a016777ad63ea
5
5
  SHA512:
6
- metadata.gz: fed4a175a284af002c5a7d960512f06fa315a4997c74cc2512edbe491b0309b0e66370c89a4a3ebf56f1910aec2791aa2cfbbcdb5407070654443208976ce32e
7
- data.tar.gz: 9060a11216f66bf85cadf56a60503e3a21878358641a4680aa35624077ff181bb9946b0e6c6cf0ac6c9b83a17e9719dadbef9d1e3760fd46a770ae967d3d5a16
6
+ metadata.gz: 79eb35957035d51c30b9f2afce0b364bec99d5276c2f2526f6e2d3ded5d31603a21815b52e128a97090cbbc58e010cf2692afe95e8d3ba7cd4c8865a87ee6797
7
+ data.tar.gz: 23e555e0d4e2fc4dd338f74faf1eec966db459d91ce56be2203e2149609ed1003dbae437cfe220971d72b313bd57ea73d2d0487f4b16a8e4801f631772e2df27
@@ -1,4 +1,18 @@
1
- ## v0.1.0 to-be-released
1
+ ## v0.1.1 2015-03-13
2
+
3
+ ### Changed
4
+
5
+ * `Transproc(:map_array)` performance improvements (splattael + solnic)
6
+ * hash transformation performance improvements (solnic)
7
+
8
+ ### Fixed
9
+
10
+ * `Transproc(:nest)` handles falsy values correctly now (solnic)
11
+ * Missing `require "time"` added (splattael)
12
+
13
+ [Compare v0.1.0...v0.1.1](https://github.com/solnic/transproc/compare/v0.1.0...v0.1.1)
14
+
15
+ ## v0.1.0 2014-12-28
2
16
 
3
17
  ### Added
4
18
 
@@ -9,7 +23,7 @@
9
23
  * boolean coercions (solnic)
10
24
  * [hash] `:nest` which wraps a set of keys under a new key (solnic)
11
25
 
12
- [Compare v0.0.1...master](https://github.com/solnic/transproc/compare/v0.0.1...master)
26
+ [Compare v0.0.1...v0.1.0](https://github.com/solnic/transproc/compare/v0.0.1...v0.1.0)
13
27
 
14
28
  ## v0.0.1 2014-12-24
15
29
 
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in transproc.gemspec
4
3
  gemspec
4
+
5
+ group :test do
6
+ gem 'codeclimate-test-reporter', require: nil
7
+ end
8
+
9
+ group :tools do
10
+ gem 'byebug', platform: :mri
11
+ gem 'benchmark-ips'
12
+ end
@@ -1,10 +1,11 @@
1
1
  module Transproc
2
2
  register(:map_array) do |array, *fns|
3
- Transproc(:map_array!, *fns)[array.dup]
3
+ Transproc(:map_array!, *fns)[Array[*array]]
4
4
  end
5
5
 
6
6
  register(:map_array!) do |array, *fns|
7
- array.map! { |value| fns.reduce(:+)[value] }
7
+ fn = fns.size == 1 ? fns[0] : fns.reduce(:+)
8
+ array.map! { |value| fn[value] }
8
9
  end
9
10
 
10
11
  register(:wrap) do |array, key, keys|
@@ -1,4 +1,5 @@
1
1
  require 'date'
2
+ require 'time'
2
3
  require 'bigdecimal'
3
4
  require 'bigdecimal/util'
4
5
 
@@ -1,6 +1,6 @@
1
1
  module Transproc
2
2
  register(:symbolize_keys) do |hash|
3
- Transproc(:symbolize_keys!)[hash.dup]
3
+ Transproc(:symbolize_keys!)[Hash[hash]]
4
4
  end
5
5
 
6
6
  register(:symbolize_keys!) do |hash|
@@ -9,7 +9,7 @@ module Transproc
9
9
  end
10
10
 
11
11
  register(:map_hash) do |hash, mapping|
12
- Transproc(:map_hash!, mapping)[hash.dup]
12
+ Transproc(:map_hash!, mapping)[Hash[hash]]
13
13
  end
14
14
 
15
15
  register(:map_hash!) do |hash, mapping|
@@ -26,12 +26,17 @@ module Transproc
26
26
  end
27
27
 
28
28
  register(:nest) do |hash, key, keys|
29
- Transproc(:nest!, key, keys)[hash.dup]
29
+ Transproc(:nest!, key, keys)[Hash[hash]]
30
30
  end
31
31
 
32
32
  register(:nest!) do |hash, root, keys|
33
- child = Hash[keys.zip(keys.map { |key| hash.delete(key) })]
34
-
35
- hash.update(root => child.values.any? ? child : nil)
33
+ nest_keys = hash.keys & keys
34
+
35
+ if nest_keys.size > 0
36
+ child = Hash[nest_keys.zip(nest_keys.map { |key| hash.delete(key) })]
37
+ hash.update(root => child)
38
+ else
39
+ hash.update(root => nil)
40
+ end
36
41
  end
37
42
  end
@@ -1,3 +1,3 @@
1
1
  module Transproc
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.1".freeze
3
3
  end
@@ -26,13 +26,36 @@ describe 'Hash mapping with Transproc' do
26
26
  end
27
27
  end
28
28
 
29
- describe 'nest!' do
29
+ describe 'nest' do
30
30
  it 'returns new hash with keys nested under a new key' do
31
- nest = Transproc(:nest!, :baz, ['foo'])
31
+ nest = Transproc(:nest, :baz, ['foo'])
32
32
 
33
33
  input = { 'foo' => 'bar' }
34
34
  output = { baz: { 'foo' => 'bar' } }
35
35
 
36
+ expect(nest[input]).to eql(output)
37
+ expect(input).to eql('foo' => 'bar')
38
+ end
39
+ end
40
+
41
+ describe 'nest!' do
42
+ it 'returns new hash with keys nested under a new key' do
43
+ nest = Transproc(:nest!, :baz, ['one', 'two', 'not-here'])
44
+
45
+ input = { 'foo' => 'bar', 'one' => nil, 'two' => false }
46
+ output = { 'foo' => 'bar', baz: { 'one' => nil, 'two' => false } }
47
+
48
+ nest[input]
49
+
50
+ expect(input).to eql(output)
51
+ end
52
+
53
+ it 'returns new hash with nil nested under a new key when nest-keys are missing' do
54
+ nest = Transproc(:nest!, :baz, ['foo'])
55
+
56
+ input = { 'bar' => 'foo' }
57
+ output = { 'bar' => 'foo', baz: nil }
58
+
36
59
  nest[input]
37
60
 
38
61
  expect(input).to eql(output)
@@ -4,3 +4,8 @@ if RUBY_ENGINE == "rbx"
4
4
  end
5
5
 
6
6
  require 'transproc/all'
7
+
8
+ begin
9
+ require 'byebug'
10
+ rescue LoadError
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: transproc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-28 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  version: '0'
104
104
  requirements: []
105
105
  rubyforge_project:
106
- rubygems_version: 2.2.2
106
+ rubygems_version: 2.4.5
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: Experimental functional transformations for Ruby
@@ -114,4 +114,3 @@ test_files:
114
114
  - spec/integration/hash_spec.rb
115
115
  - spec/integration/transproc_spec.rb
116
116
  - spec/spec_helper.rb
117
- has_rdoc: