jr-cli 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -4
  3. data/bin/jr +2 -0
  4. data/lib/jr/cli/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3e9c0a3d80b3402fe9d7eed9c291bfbb879d906b
4
- data.tar.gz: e3288ed72a7e928839b06fdc7bda4888bfec886b
3
+ metadata.gz: 571f0ebed46056b1357383e6ad9161fe330057e7
4
+ data.tar.gz: 17742313424d2d177a5a97058b8f54e10d693ae8
5
5
  SHA512:
6
- metadata.gz: a1b1d1afdf96a5c1743fc52431e51a35396548d4c04aca525f87581d0611f29ad6ea6a9141d39ab565cb792b8e6136589e6d1135d93a3c128d0ea17a2b621af8
7
- data.tar.gz: 02d62467015405fe56247703e881d254c3e0bfa57e49e9da5347de46340f0fd2769b7ebd0afa06bb76fd477356f574c24d1106a1dff4f42c6bcbb31e510a063b
6
+ metadata.gz: 8386745b224fb617bbde00c45b96e2c1dbb57afdb1cc4f74b0ccd6bb425440dbf8aff9790d22e05a92cb35edd9fd814dfccf09461c00f73263b967e531739129
7
+ data.tar.gz: 8b38c081c77377d95a720bb3dd58c14a253a53c2fbc9b9ffe52cc87fcc73e7238f32cca9850c31a5ff966e424fc4877083f68cfb4d674753578884f8f72b8bf0
data/README.md CHANGED
@@ -41,20 +41,22 @@ $ curl -s 'https://api.github.com/users/yuya-takeyama/repos' > repos.json
41
41
 
42
42
  ### show repositories
43
43
 
44
- Because response from `GET /users/:username/repos` is wrapped with `Array`, select the first element.
44
+ Because response from `GET /users/:username/repos` is wrapped with `Array`, flatten it by `#flat_map`.
45
45
  You'll get stream of JSON reperesents repositories.
46
46
 
47
47
  ```
48
- $ jr 'first' repos.json
48
+ $ jr 'flat_map(&:itself)' repos.json
49
49
  ```
50
50
 
51
+ Pro Tip: `Kernel#itself` is an identity function implemented in Ruby 2.2.0, but `jr` provides it for Ruby 2.1.0 or earlier versions.
52
+
51
53
  ### map to reduce data
52
54
 
53
55
  Default response has too much informations.
54
56
  So reduce data using `#map` method.
55
57
 
56
58
  ```
57
- $ ./bin/jr 'first.map{|j| {name: j[:name], desc: j[:description], lang: j[:language]} }' repos.json
59
+ $ jr 'flat_map(&:itself).map{|j| {name: j[:name], desc: j[:description], lang: j[:language]} }' repos.json
58
60
  {
59
61
  "name": "acne",
60
62
  "desc": "Simple DI container for PHP < 5.3",
@@ -84,7 +86,7 @@ Repositories have its primary language which is detected automatically.
84
86
  Let's aggregate it and count by languages.
85
87
 
86
88
  ```
87
- $ ./bin/jr 'first.map{|j| {name: j[:name], desc: j[:description], lang: j[:language]} }.reduce({}){|acc, j| l = j[:lang]; acc[l] ||= 0; acc[l] += 1; acc }' repos.json
89
+ $ jr 'flat_map(&:itself).map{|j| {name: j[:name], desc: j[:description], lang: j[:language]} }.group_by{|j| j[:lang] }.map{|l, v| [l, v.size ] }.to_h' repos.json
88
90
  {
89
91
  "PHP": 10,
90
92
  "Ruby": 12,
data/bin/jr CHANGED
@@ -15,6 +15,8 @@ unless Kernel.respond_to? :itself
15
15
  end
16
16
  end
17
17
 
18
+ trap('INT') { exit 130 }
19
+
18
20
  inputs = ARGV[1] ? ARGV[1..-1].map {|f| open f } : [STDIN]
19
21
  result = Enumerator.new do |yielder|
20
22
  inputs.each do |input|
@@ -1,5 +1,5 @@
1
1
  module Jr
2
2
  module Cli
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jr-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuya Takeyama
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-05 00:00:00.000000000 Z
11
+ date: 2014-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby