zweikopf 0.0.4 → 0.0.5

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.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Zweihopf, a two-headed JVM friend of yours.
2
+ [![Continuous Integration status](https://secure.travis-ci.org/ifesdjeen/zweikopf.png)](http://travis-ci.org/ifesdjeen/zweikopf)
2
3
 
3
4
  Zweikopf helps you to interoperate between Clojure and JRuby on JVM.
4
5
 
@@ -16,16 +17,65 @@ Or install it yourself as:
16
17
 
17
18
  $ gem install zweikopf
18
19
 
20
+ ## Usage
21
+
22
+ Transfroming from Clojure entities to Ruby ones is as easy as:
23
+
24
+ ```ruby
25
+ # Say you have a variable clojure_var that is a Clojure Hash: {:a 1 :b 2}
26
+ Zweikopf::Transformer.from_clj(clojure_var)
27
+ # => {:a => 1, :b => 2}
28
+
29
+ # Or an array: [1 2 3 4 5]
30
+ Zweikopf::Transformer.from_clj(clojure_var)
31
+ # => [1, 2, 3, 4, 5]
32
+
33
+ # Or something really wicked: {:a 1 :b {:c [{:d 2} {:e 3} {:f 4}]}}
34
+ Zweikopf::Transformer.from_clj(clojure_var)
35
+ # => {:a => 1, :b => {:c => [{:d => 2}, {:e => 3}, { :f => 4}]}}
36
+ ```
37
+
38
+ And backwards:
39
+
40
+ ```ruby
41
+ # Say you have a variable ruby_var that is a Ruby Hash: {:a => 1, :b => 2}
42
+ Zweikopf::Transformer.from_ruby(ruby_var)
43
+ # => {:a 1 :b 2}
44
+
45
+ # Or an array: [1, 2, 3, 4, 5]
46
+ Zweikopf::Transformer.from_ruby(ruby_var)
47
+ # => [1 2 3 4 5]
48
+
49
+ # Or something really wicked: {:a => 1, :b => {:c => [{:d => 2}, {:e => 3}, { :f => 4}]}}
50
+ Zweikopf::Transformer.from_ruby(ruby_var)
51
+ # => {:a 1 :b {:c [{:d 2} {:e 3} {:f 4}]}}
52
+ ```
53
+
54
+ When performing Ruby to Clojure transformation, you may leave out some space for customization:
55
+
56
+ ```ruby
57
+ class CustomTransformedEntry
58
+ def serializable_hash
59
+ {:c => 3, :d => 4}
60
+ end
61
+ end
62
+
63
+ Zweikopf::Transformer.from_ruby({:a => 1, :b => CustomTransformedEntry.new }) do |v|
64
+ if v.is_a?(CustomTransformedEntry)
65
+ v.serializable_hash
66
+ else
67
+ v
68
+ end
69
+ end
70
+ # => {:a 1 :b {:c 3 :d 4}}
71
+ ```
72
+
19
73
  # Performance
20
74
 
21
75
  ## Conversion from Ruby hash to Clojure PersistentHash Map
22
76
 
23
77
  Most of time 52% according to the rough estimate is spent while converting from ruby Symbol to clojure Keyword.
24
78
 
25
- ## Usage
26
-
27
- TODO: Write usage instructions here
28
-
29
79
  ## Contributing
30
80
 
31
81
  1. Fork it
@@ -3,16 +3,16 @@ java_import "clojure.lang.PersistentVector"
3
3
  module Zweikopf
4
4
  module Array
5
5
 
6
- def self.from_ruby(arr)
6
+ def self.from_ruby(arr, &block)
7
7
  PersistentVector.create(arr.inject([]) do |acc, v|
8
- acc<< Zweikopf::Transformer.from_ruby(v)
8
+ acc<< Zweikopf::Transformer.from_ruby(v, &block)
9
9
  end)
10
10
  end # to_persistent_vector
11
11
 
12
- def self.from_clj(clj_arr)
12
+ def self.from_clj(clj_arr, &block)
13
13
  [].tap do |ruby_arr|
14
14
  clj_arr.each do |v|
15
- ruby_arr<< Zweikopf::Transformer.from_clj(v);
15
+ ruby_arr<< Zweikopf::Transformer.from_clj(v, &block);
16
16
  end
17
17
  end
18
18
  end # self.from_clj
@@ -1,3 +1,3 @@
1
1
  module Zweikopf
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,115 +1,119 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: zweikopf
3
- version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 0.0.4
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.5
6
6
  platform: ruby
7
- authors:
8
- - Oleksandr Petrov
9
- autorequire:
7
+ authors:
8
+ - Oleksandr Petrov
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-09-07 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: rake
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
19
- none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
24
- type: :development
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: rspec
28
- prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
30
- none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
35
- type: :development
36
- version_requirements: *id002
12
+ date: 2012-09-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ none: false
28
+ prerelease: false
29
+ type: :development
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ none: false
44
+ prerelease: false
45
+ type: :development
37
46
  description: Rubygem for jruby/clojure interop
38
- email:
39
- - oleksandr.petrov@gmail.com
47
+ email:
48
+ - oleksandr.petrov@gmail.com
40
49
  executables: []
41
-
42
50
  extensions: []
43
-
44
51
  extra_rdoc_files: []
45
-
46
- files:
47
- - .gitignore
48
- - .rspec
49
- - .rvmrc
50
- - .travis.yml
51
- - Gemfile
52
- - LICENSE
53
- - README.md
54
- - Rakefile
55
- - deps/clojure-1.4.0.jar
56
- - lib/zweikopf.rb
57
- - lib/zweikopf/array.rb
58
- - lib/zweikopf/hash.rb
59
- - lib/zweikopf/keyword.rb
60
- - lib/zweikopf/primitive.rb
61
- - lib/zweikopf/transformer.rb
62
- - lib/zweikopf/version.rb
63
- - project.clj
64
- - spec/fixtures/clj_array1.clj
65
- - spec/fixtures/clj_deep_hash1.clj
66
- - spec/fixtures/clj_hash1.clj
67
- - spec/fixtures/complex_hash.clj
68
- - spec/fixtures/empty_hash.clj
69
- - spec/spec_helper.rb
70
- - spec/support/loader.rb
71
- - spec/zweikopf/performance_spec.rb
72
- - spec/zweikopf/transformer_clojure_to_ruby_spec.rb
73
- - spec/zweikopf/transformer_ruby_to_clojure_spec.rb
74
- - src/zweikopf/core.clj
75
- - test/zweikopf/core_test.clj
76
- - zweikopf.gemspec
77
- homepage: ""
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - .rvmrc
56
+ - .travis.yml
57
+ - Gemfile
58
+ - LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - deps/clojure-1.4.0.jar
62
+ - lib/zweikopf.rb
63
+ - lib/zweikopf/array.rb
64
+ - lib/zweikopf/hash.rb
65
+ - lib/zweikopf/keyword.rb
66
+ - lib/zweikopf/primitive.rb
67
+ - lib/zweikopf/transformer.rb
68
+ - lib/zweikopf/version.rb
69
+ - project.clj
70
+ - spec/fixtures/clj_array1.clj
71
+ - spec/fixtures/clj_deep_hash1.clj
72
+ - spec/fixtures/clj_hash1.clj
73
+ - spec/fixtures/complex_hash.clj
74
+ - spec/fixtures/empty_hash.clj
75
+ - spec/spec_helper.rb
76
+ - spec/support/loader.rb
77
+ - spec/zweikopf/performance_spec.rb
78
+ - spec/zweikopf/transformer_clojure_to_ruby_spec.rb
79
+ - spec/zweikopf/transformer_ruby_to_clojure_spec.rb
80
+ - src/zweikopf/core.clj
81
+ - test/zweikopf/core_test.clj
82
+ - zweikopf.gemspec
83
+ homepage: ''
78
84
  licenses: []
79
-
80
- post_install_message:
85
+ post_install_message:
81
86
  rdoc_options: []
82
-
83
- require_paths:
84
- - lib
85
- required_ruby_version: !ruby/object:Gem::Requirement
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
86
94
  none: false
87
- requirements:
88
- - - ">="
89
- - !ruby/object:Gem::Version
90
- version: "0"
91
- required_rubygems_version: !ruby/object:Gem::Requirement
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ! '>='
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
92
100
  none: false
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: "0"
97
101
  requirements: []
98
-
99
- rubyforge_project:
102
+ rubyforge_project:
100
103
  rubygems_version: 1.8.24
101
- signing_key:
104
+ signing_key:
102
105
  specification_version: 3
103
106
  summary: Its good, try it out!
104
- test_files:
105
- - spec/fixtures/clj_array1.clj
106
- - spec/fixtures/clj_deep_hash1.clj
107
- - spec/fixtures/clj_hash1.clj
108
- - spec/fixtures/complex_hash.clj
109
- - spec/fixtures/empty_hash.clj
110
- - spec/spec_helper.rb
111
- - spec/support/loader.rb
112
- - spec/zweikopf/performance_spec.rb
113
- - spec/zweikopf/transformer_clojure_to_ruby_spec.rb
114
- - spec/zweikopf/transformer_ruby_to_clojure_spec.rb
115
- - test/zweikopf/core_test.clj
107
+ test_files:
108
+ - spec/fixtures/clj_array1.clj
109
+ - spec/fixtures/clj_deep_hash1.clj
110
+ - spec/fixtures/clj_hash1.clj
111
+ - spec/fixtures/complex_hash.clj
112
+ - spec/fixtures/empty_hash.clj
113
+ - spec/spec_helper.rb
114
+ - spec/support/loader.rb
115
+ - spec/zweikopf/performance_spec.rb
116
+ - spec/zweikopf/transformer_clojure_to_ruby_spec.rb
117
+ - spec/zweikopf/transformer_ruby_to_clojure_spec.rb
118
+ - test/zweikopf/core_test.clj
119
+ ...