nogizaka_blog 0.0.3 → 0.0.4

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: 7af5a4fb1fdaf3e6fa45cb1b82edae8bc59ca3a3
4
- data.tar.gz: e418bcae7b1821a41db956290b880a5ae3e30905
3
+ metadata.gz: 923417f0f312efd604e0c5b3606bfc33a9abe8ff
4
+ data.tar.gz: 9ce486df6746b1afbc587cc72273d5aae6430ff2
5
5
  SHA512:
6
- metadata.gz: b17361c2f0ef31f909e24fca17c36336c099c7677b0d85ee8adeaa8f018b2f1e11137f163be2b71667e0c2d536864535c062bee74902029517f14a3d59115918
7
- data.tar.gz: cf948afe92a0a2975bba2abbcf27cfb5c236fc6c25037402eddd385a5da56afa6b8b90d75aaf2d5d6a38d05811f58cc6c825aa80ad30b9af799917f22bb94de8
6
+ metadata.gz: d8eb0863381a7597144d55d69f35dc2169510fd838667300c824f5ae6a9646baffeb63b149587b6a968692bb7e70f1886c57b3a32b409b42929f555b59d1285f
7
+ data.tar.gz: 69f63bfc7fee30cdf5c39ab44840426c390b988938348d4444ccb1f3bd6a8774b56c12f718059d975784b570451ffb58769851613066442115f1f36a4e68aadc
data/README.md CHANGED
@@ -18,11 +18,36 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- $ nogizaka_blog yearmonth 201405
22
-
23
- Generate JSON
24
-
25
- $ nogizaka_blog yearmonth 201405 --json
21
+ require 'nogizaka_blog'
22
+
23
+ nogi = NogizakaBlog::Amazing.new('201405')
24
+
25
+ nogi.scraping do |name, comment, article, index|
26
+ puts "#{index} #{name.to_kanji}(#{name}) #{comment} / #{article}"
27
+ end
28
+
29
+ Generate JSON example
30
+
31
+ require 'nogizaka_blog'
32
+
33
+ @nogi = NogizakaBlog::Amazing.new('201405')
34
+
35
+ p @nogi.member_size
36
+
37
+ def gen_json
38
+ last = @nogi.member_size - 1
39
+ print '['
40
+ @nogi.scraping do |name, comment, article, idx|
41
+ if idx == last
42
+ print %Q({"name": "#{name.to_kanji}", "comment": #{comment}, "article": #{article}})
43
+ else
44
+ print %Q({"name": "#{name.to_kanji}", "comment": #{comment}, "article": #{article}},)
45
+ end
46
+ end
47
+ print ']'
48
+ end
49
+
50
+ gen_json
26
51
 
27
52
  ## Contributing
28
53
 
data/Rakefile CHANGED
@@ -1,2 +1 @@
1
- require "bundler/gem_tasks"
2
-
1
+ require 'bundler/gem_tasks'
@@ -6,15 +6,16 @@ module NogizakaBlog
6
6
  class Amazing
7
7
  using Extentions
8
8
 
9
+ attr_reader :member_size
10
+ attr_accessor :yearmonth
11
+
9
12
  def initialize(yearmonth)
10
13
  @yearmonth = yearmonth
11
14
  @member_size = MEMBER.size
12
15
  end
13
16
 
14
- attr_reader :member_size
15
-
16
17
  def scraping
17
- get_max_page
18
+ max_page
18
19
  @member_max.each_with_index do |(name, max), idx|
19
20
  @comment = []
20
21
 
@@ -23,11 +24,11 @@ module NogizakaBlog
23
24
  @comment << 0
24
25
  elsif max == 0
25
26
  url = "http://blog.nogizaka46.com/#{name}/?d=#{@yearmonth}"
26
- get_comment_size(url)
27
+ comment_size(url)
27
28
  else
28
29
  (1..max).each do |n|
29
30
  url = "http://blog.nogizaka46.com/#{name}/?p=#{n}&d=#{@yearmonth}"
30
- get_comment_size(url)
31
+ comment_size(url)
31
32
  end
32
33
  end
33
34
 
@@ -43,30 +44,7 @@ module NogizakaBlog
43
44
 
44
45
  private
45
46
 
46
- def run
47
- puts "#{@yearmonth[0..3]}/#{@yearmonth[4..5]}"
48
- header = display_format('name', 'comment', 'article')
49
- puts header
50
- puts '-' * header.size
51
- scraping do |name, comment, article, _|
52
- puts display_format("#{name.to_kanji}(#{name})", comment, article)
53
- end
54
- end
55
-
56
- def gen_json
57
- last = @member_size - 1
58
- print "["
59
- scraping do |name, comment, article, idx|
60
- if idx == last
61
- print "{\"name\": \"#{name.to_kanji}\", \"comment\": #{comment}, \"article\": #{article}}"
62
- else
63
- print "{\"name\": \"#{name.to_kanji}\", \"comment\": #{comment}, \"article\": #{article}},"
64
- end
65
- end
66
- print "]"
67
- end
68
-
69
- def get_max_page
47
+ def max_page
70
48
  nbsp = Nokogiri::HTML('&nbsp;').text
71
49
  @member_max = []
72
50
 
@@ -95,20 +73,11 @@ module NogizakaBlog
95
73
  end
96
74
  end
97
75
 
98
- def get_comment_size(url)
76
+ def comment_size(url)
99
77
  doc = Nokogiri::HTML(open(url))
100
78
  doc.css('.entrybottom a:last').each do |link|
101
79
  link.content.scan(/\d+/) { |c| @comment << c }
102
80
  end
103
81
  end
104
-
105
- def display_format(name, comment, article)
106
- name_length = 28 - full_width_count(name)
107
- [name.ljust(name_length), comment.to_s.rjust(7), article.to_s.rjust(7)].join(' | ')
108
- end
109
-
110
- def full_width_count(string)
111
- string.each_char.select { |char| !(/[ -~。-゚]/.match(char)) }.count
112
- end
113
82
  end
114
83
  end
@@ -1,11 +1,11 @@
1
+ class String
2
+ def to_kanji
3
+ NogizakaBlog::MEMBER[self]
4
+ end
5
+ end
6
+
1
7
  module NogizakaBlog
2
8
  module Extentions
3
- refine String do
4
- def to_kanji
5
- MEMBER[self]
6
- end
7
- end
8
-
9
9
  refine Array do
10
10
  def sum
11
11
  map(&:to_i).inject(:+)
@@ -1,3 +1,3 @@
1
1
  module NogizakaBlog
2
- MEMBER = {"manatsu.akimoto"=>"秋元真夏", "erika.ikuta"=>"生田絵梨花", "rina.ikoma"=>"生駒里奈", "rena.ichiki"=>"市來玲奈", "nene.ito"=>"伊藤寧々", "marika.ito"=>"伊藤万理華", "sayuri.inoue"=>"井上小百合", "misa.eto"=>"衛藤美彩", "hina.kawago"=>"川後陽菜", "mahiro.kawamura"=>"川村真洋", "hinako.kitano"=>"北野日奈子", "asuka.saito"=>"齋藤飛鳥", "chiharu.saito"=>"斎藤ちはる", "yuuri.saito"=>"斉藤優里", "reika.sakurai"=>"桜井玲香", "mai.shiraishi"=>"白石麻衣", "mai.shinuchi"=>"新内眞衣", "kazumi.takayama"=>"高山一実", "kana.nakada"=>"中田花奈", "himeka.nakamoto"=>"中元日芽香", "seira.nagashima"=>"永島聖羅", "nanase.nishino"=>"西野七瀬", "ami.noujo"=>"能條愛未", "nanami.hashimoto"=>"橋本奈々未", "seira.hatanaka"=>"畠中清羅", "hina.higuchi"=>"樋口日奈", "mai.fukagawa"=>"深川麻衣", "minami.hoshino"=>"星野みなみ", "miona.hori"=>"堀未央奈", "sayuri.matsumura"=>"松村沙友理", "rina.yamato"=>"大和里菜", "yumi.wakatsuki"=>"若月佑美", "maaya.wada"=>"和田まあや"}.freeze
2
+ MEMBER = { 'manatsu.akimoto' => '秋元真夏', 'erika.ikuta' => '生田絵梨花', 'rina.ikoma' => '生駒里奈', 'rena.ichiki' => '市來玲奈', 'nene.ito' => '伊藤寧々', 'marika.ito' => '伊藤万理華', 'sayuri.inoue' => '井上小百合', 'misa.eto' => '衛藤美彩', 'hina.kawago' => '川後陽菜', 'mahiro.kawamura' => '川村真洋', 'hinako.kitano' => '北野日奈子', 'asuka.saito' => '齋藤飛鳥', 'chiharu.saito' => '斎藤ちはる', 'yuuri.saito' => '斉藤優里', 'reika.sakurai' => '桜井玲香', 'mai.shiraishi' => '白石麻衣', 'mai.shinuchi' => '新内眞衣', 'kazumi.takayama' => '高山一実', 'kana.nakada' => '中田花奈', 'himeka.nakamoto' => '中元日芽香', 'seira.nagashima' => '永島聖羅', 'nanase.nishino' => '西野七瀬', 'ami.noujo' => '能條愛未', 'nanami.hashimoto' => '橋本奈々未', 'seira.hatanaka' => '畠中清羅', 'hina.higuchi' => '樋口日奈', 'mai.fukagawa' => '深川麻衣', 'minami.hoshino' => '星野みなみ', 'miona.hori' => '堀未央奈', 'sayuri.matsumura' => '松村沙友理', 'rina.yamato' => '大和里菜', 'yumi.wakatsuki' => '若月佑美', 'maaya.wada' => '和田まあや' }.freeze
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module NogizakaBlog
2
- VERSION = "0.0.3"
2
+ VERSION = '0.0.4'
3
3
  end
data/lib/nogizaka_blog.rb CHANGED
@@ -2,4 +2,3 @@ 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'
@@ -4,22 +4,21 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'nogizaka_blog/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "nogizaka_blog"
7
+ spec.name = 'nogizaka_blog'
8
8
  spec.version = NogizakaBlog::VERSION
9
- spec.authors = ["hachy"]
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}
13
- spec.homepage = "https://github.com/hachy/nogizaka_blog"
14
- spec.license = "MIT"
9
+ spec.authors = ['hachy']
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)
13
+ spec.homepage = 'https://github.com/hachy/nogizaka_blog'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'thor'
22
21
  spec.add_dependency 'nokogiri'
23
- spec.add_development_dependency "bundler", "~> 1.6"
24
- spec.add_development_dependency "rake"
22
+ spec.add_development_dependency 'bundler', '~> 1.6'
23
+ spec.add_development_dependency 'rake'
25
24
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nogizaka_blog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - hachy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-21 00:00:00.000000000 Z
11
+ date: 2014-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: thor
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: nokogiri
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -82,7 +68,6 @@ files:
82
68
  - bin/nogizaka_blog
83
69
  - lib/nogizaka_blog.rb
84
70
  - lib/nogizaka_blog/amazing.rb
85
- - lib/nogizaka_blog/cli.rb
86
71
  - lib/nogizaka_blog/core_ext.rb
87
72
  - lib/nogizaka_blog/member.rb
88
73
  - lib/nogizaka_blog/version.rb
@@ -1,25 +0,0 @@
1
- require 'thor'
2
-
3
- module NogizakaBlog
4
- class CLI < Thor
5
- desc "yearmonth YEARMONTH", "show the number of comments and articles of Nogizaka46's blog"
6
- option :json, :type => :boolean, :aliases => '-j'
7
- def yearmonth(ym)
8
- nogizaka = NogizakaBlog::Amazing.new(ym)
9
- if options[:json]
10
- nogizaka.__send__ :gen_json
11
- else
12
- nogizaka.__send__ :run
13
- end
14
- end
15
- map %w(-y --yearmonth) => :yearmonth
16
-
17
- desc "version", "show NogizakaBlog version"
18
- def version
19
- puts "NogizakaBlog #{NogizakaBlog::VERSION}"
20
- end
21
- map %w(-v --version) => :version
22
- end
23
-
24
- CLI.start(ARGV)
25
- end