juxt 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -5,11 +5,19 @@ A simple gem to provide juxtaposition to Objects and Arrays
5
5
  Example
6
6
 
7
7
  ```ruby
8
- ['foo', 'bar'].map_juxt :upcase, :reverse
9
- # [['FOO', 'oof'], ['BAR', 'rab']]
8
+ ['foo', 'bar'].map_juxt :upcase, :reverse
9
+ # [['FOO', 'oof'], ['BAR', 'rab']]
10
10
 
11
- 'foo'.juxt :upcase, :reverse
12
- # ['FOO', 'oof']
11
+ 'foo'.juxt :upcase, :reverse
12
+ # ['FOO', 'oof']
13
+
14
+ {:foo => 'foo', :bar => 'bar'}.juxt :foo, :bar
15
+ # ['foo', 'bar']
16
+
17
+ # Need to create a hash from some Object properties?
18
+ a = ['foo', 'bar'].map_juxt :upcase, :reverse
19
+ Hash[a]
20
+ # {'FOO' => 'oof', 'BAR' => 'rab'}
13
21
  ```
14
22
 
15
23
  ## Installation
data/lib/juxt/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Juxt
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/juxt.rb CHANGED
@@ -1,15 +1,20 @@
1
1
  require "juxt/version"
2
2
 
3
- class Array
4
- def map_juxtapose(*args)
5
- map{ |e| [*args].map{ |x| e.send x } }
6
- end
7
- alias map_juxt map_juxtapose
8
- end
9
-
10
3
  class Object
11
4
  def juxtapose(*args)
12
- [*args].map{ |x| send x }
5
+ [*args].map do |x|
6
+ case self
7
+ when Hash then self[x.to_sym] || self[x.to_s] || self[x]
8
+ else send x
9
+ end
10
+ end
13
11
  end
14
12
  alias juxt juxtapose
15
13
  end
14
+
15
+ class Array
16
+ def map_juxtapose(*args)
17
+ map{ |e| e.juxtapose *args }
18
+ end
19
+ alias map_juxt map_juxtapose
20
+ end
data/spec/juxt_spec.rb CHANGED
@@ -4,7 +4,8 @@ describe Juxt do
4
4
  let(:arr1){ ['foo', 'bar'] }
5
5
  let(:arr2){ ['foo'] }
6
6
  let(:arr3){ [] }
7
- let(:obj){ 'foo' }
7
+ let(:obj1){ 'foo' }
8
+ let(:obj2){ {:foo => 'foo', :bar => 'bar'} }
8
9
 
9
10
  describe 'Array#map_juxt' do
10
11
  specify{ expect(arr1.map_juxt :upcase, :reverse).to eq [['FOO', 'oof'], ['BAR', 'rab']] }
@@ -13,6 +14,12 @@ describe Juxt do
13
14
  end
14
15
 
15
16
  describe 'Object#juxt' do
16
- specify{ expect(obj.juxt :upcase, :reverse).to eq ['FOO', 'oof'] }
17
+ describe String do
18
+ specify{ expect(obj1.juxt :upcase, :reverse).to eq ['FOO', 'oof'] }
19
+ end
20
+
21
+ describe Hash do
22
+ specify{ expect(obj2.juxt :foo, :bar).to eq ['foo', 'bar'] }
23
+ end
17
24
  end
18
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: juxt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: