nogizaka_blog 0.1.5 → 0.1.6

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: 973ac557cb48d5056fa14f8b49f276706c5fcff4
4
- data.tar.gz: eebda70f666a82d4ebd2bfe2e381e3046896a3fd
3
+ metadata.gz: dbe76780e0a1b57facd3805cd814a8a91d1d56b5
4
+ data.tar.gz: f8049d999e5e9db88f72c152d65c43017fae4f96
5
5
  SHA512:
6
- metadata.gz: b8d64778115d10557ababf94f4c5f59d149295e68134481dbbb3a50668984b194c7064c3dfd55cdcb854eb0c51d63c5a3878d8cef437140098d2b98d67cdeb5f
7
- data.tar.gz: ef52a6e4896ef82f78c20ce9a01a2ac74b6c627f5d117ad0962fab22e9b68df39bf536357254c241bda49222f36ec3c1a83cd38e67fdd72dfbffe71bbb2df49d
6
+ metadata.gz: 216c2cb2dfaca1d741143c411721f4d7c19ec7a0cf9b22c1d2749a69d8b325569eee4b5775dd8cab236cf1588422650e2e993f51cf63946aa0c7f1165fbb68d2
7
+ data.tar.gz: d61b73c17698cfdc3cb748db91c10475547bc0830f511b09a4178ec5085f4022131a571016253feccf537089b68ba629ef79b5c9197edd113930074b95db53c6
data/README.md CHANGED
@@ -54,6 +54,16 @@ end
54
54
  gen_json
55
55
  ```
56
56
 
57
+ ### CLI
58
+
59
+ Basic usage in Terminal
60
+
61
+ $ nogizaka_blog when YEARMONTH [--sort comment/article]
62
+
63
+ (e.g. September 2015)
64
+
65
+ $ nogizaka_blog when 201509
66
+
57
67
  ## Contributing
58
68
 
59
69
  1. Fork it ( https://github.com/[my-github-username]/nogizaka_blog/fork )
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "nogizaka_blog"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -1,3 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'nogizaka_blog'
4
+
5
+ NogizakaBlog::CLI.start(ARGV)
@@ -0,0 +1,70 @@
1
+ require 'thor'
2
+
3
+ module NogizakaBlog
4
+ Thread.abort_on_exception = true
5
+
6
+ class CLI < Thor
7
+ GLYPHS = %w(| / - \\ | / - \\)
8
+
9
+ desc 'when YEARMONTH', 'Show the number of comments and articles'
10
+ method_option :sort, aliases: '-s', desc: 'set comment or article'
11
+ def when(yearmonth)
12
+ @nogi = Amazing.new(yearmonth)
13
+ print_header
14
+ spinner
15
+ case options[:sort]
16
+ when 'comment' then sort_by_comment
17
+ when 'article' then sort_by_article
18
+ else normal
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def print_header
25
+ ym = @nogi.yearmonth
26
+ puts "#{ym[0..3]}/#{ym[4..5]}"
27
+ head = display_format('name', 'comment', 'article')
28
+ puts head
29
+ puts '-' * head.size
30
+ end
31
+
32
+ def spinner
33
+ Thread.new do
34
+ loop do
35
+ GLYPHS.each do |glyph|
36
+ print "processing.. #{glyph}\r"
37
+ sleep 0.15
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def normal
44
+ @nogi.each do |name, comment, article|
45
+ puts display_format("#{name.to_kanji}", comment, article)
46
+ end
47
+ end
48
+
49
+ def sort_by_comment
50
+ @nogi.sort_by { |_, b, _| b }.reverse_each do |name, comment, article|
51
+ puts display_format("#{name.to_kanji}", comment, article)
52
+ end
53
+ end
54
+
55
+ def sort_by_article
56
+ @nogi.sort_by { |_, _, c| c }.reverse_each do |name, comment, article|
57
+ puts display_format("#{name.to_kanji}", comment, article)
58
+ end
59
+ end
60
+
61
+ def display_format(name, comment, article)
62
+ name_length = 10 - full_width_count(name)
63
+ [name.ljust(name_length), comment.to_s.rjust(7), article.to_s.rjust(7)].join(' | ')
64
+ end
65
+
66
+ def full_width_count(string)
67
+ string.each_char.count { |char| !(/[ -~。-゚]/.match(char)) }
68
+ end
69
+ end
70
+ end
@@ -1,3 +1,3 @@
1
1
  module NogizakaBlog
2
- VERSION = '0.1.5'
2
+ VERSION = '0.1.6'
3
3
  end
data/lib/nogizaka_blog.rb CHANGED
@@ -2,3 +2,4 @@ require 'nogizaka_blog/version'
2
2
  require 'nogizaka_blog/member'
3
3
  require 'nogizaka_blog/core_ext'
4
4
  require 'nogizaka_blog/amazing'
5
+ require 'nogizaka_blog/cli'
@@ -8,17 +8,18 @@ Gem::Specification.new do |spec|
8
8
  spec.version = NogizakaBlog::VERSION
9
9
  spec.authors = ['hachy']
10
10
  spec.email = ['pekoett@gmail.com']
11
- spec.summary = %q(Get the number of comments and articles per month from Nogizaka46's blog)
12
- spec.description = %q(Get the number of comments and articles per month from Nogizaka46's blog)
11
+ spec.summary = %(Get the number of comments and articles per month from Nogizaka46's blog)
12
+ spec.description = %(Get the number of comments and articles per month from Nogizaka46's blog)
13
13
  spec.homepage = 'https://github.com/hachy/nogizaka_blog'
14
14
  spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_dependency 'nokogiri'
22
+ spec.add_dependency 'thor'
22
23
  spec.add_development_dependency 'bundler', '~> 1.6'
23
24
  spec.add_development_dependency 'rake'
24
25
  spec.add_development_dependency 'rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nogizaka_blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - hachy
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-21 00:00:00.000000000 Z
11
+ date: 2015-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,15 +94,16 @@ files:
80
94
  - LICENSE.txt
81
95
  - README.md
82
96
  - Rakefile
83
- - bin/nogizaka_blog
97
+ - bin/console
98
+ - bin/setup
99
+ - exe/nogizaka_blog
84
100
  - lib/nogizaka_blog.rb
85
101
  - lib/nogizaka_blog/amazing.rb
102
+ - lib/nogizaka_blog/cli.rb
86
103
  - lib/nogizaka_blog/core_ext.rb
87
104
  - lib/nogizaka_blog/member.rb
88
105
  - lib/nogizaka_blog/version.rb
89
106
  - nogizaka_blog.gemspec
90
- - spec/nogizaka_blog_spec.rb
91
- - spec/spec_helper.rb
92
107
  homepage: https://github.com/hachy/nogizaka_blog
93
108
  licenses:
94
109
  - MIT
@@ -113,6 +128,4 @@ rubygems_version: 2.4.5.1
113
128
  signing_key:
114
129
  specification_version: 4
115
130
  summary: Get the number of comments and articles per month from Nogizaka46's blog
116
- test_files:
117
- - spec/nogizaka_blog_spec.rb
118
- - spec/spec_helper.rb
131
+ test_files: []
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe NogizakaBlog do
4
- describe 'Instance' do
5
- it do
6
- nogi = NogizakaBlog::Amazing.new(201508)
7
- expect(nogi).to be_a(Enumerable)
8
- end
9
- end
10
-
11
- describe 'Extensions to String' do
12
- it 'to_kanji' do
13
- expect('manatsu.akimoto'.to_kanji).to eq('秋元真夏')
14
- end
15
- end
16
-
17
- describe 'Extensions to Array' do
18
- using NogizakaBlog::Extensions if RUBY_VERSION >= '2.1.0'
19
-
20
- it 'sum' do
21
- ary = %w(1 2 3 4 5)
22
- expect(ary.sum).to eq(15)
23
- end
24
- end
25
- end
data/spec/spec_helper.rb DELETED
@@ -1,2 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'nogizaka_blog'