ncode-syosetu 0.0.7 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 628626e9faf3c021eb1d396de9376d8506749dd7
4
- data.tar.gz: c24854c948d1844c9640e1ad14470d399d548fd7
3
+ metadata.gz: 7878afee83d88e650e0b1f1488a420b6ec6cf15d
4
+ data.tar.gz: 421172cf50e85e756cf202d216ec6876f56c0449
5
5
  SHA512:
6
- metadata.gz: d543ac26ba8a879c1cb5126ac41d30b29e6dde1944b0d3d0c69390928bbd4b3fdbc784acde7b925b9dd53694239d7638aee475e957f19814fdb20e15febaadb9
7
- data.tar.gz: 56c987e901e5d496b98638c466789db6b54a597ec5e0fa54edbad209d154663ef9618c7c1881ac2cc04049e78abcae696b04bd2096be5766324f25912f3ff3a5
6
+ metadata.gz: 313c36a8ab8e176496de81fb8d162703d3fccdb1452874aada1a0246657c691e1fc7e0e1c84550e97f8840e23960ba1dacd7bbb5213b6f080a9ceb60edb18b03
7
+ data.tar.gz: 24affcc9d308cd8f4bf9f784c3a62a1423d269dffef84040e28e86a92cbda102988bf1a89cf4296c06a350302a653523f5f0837fc8b9da1846cb41cc8ec7b354
data/.gitignore CHANGED
@@ -1,3 +1,9 @@
1
- /pkg
2
- /tmp
3
- Gemfile.lock
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -1,5 +1,5 @@
1
+ sudo: false
1
2
  language: ruby
2
3
  rvm:
3
- - 2.0.0
4
- - 2.1.0
5
- - 2.2.0
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.7
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in tataki.gemspec
3
+ # Specify your gem's dependencies in ncode-syosetu.gemspec
4
4
  gemspec
@@ -1,22 +1,21 @@
1
- Copyright (c) 2013 Sunao Komuro
1
+ The MIT License (MIT)
2
2
 
3
- MIT License
3
+ Copyright (c) 2017 hogelog
4
4
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
12
11
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
15
14
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,16 +1,41 @@
1
- # ncode-syosetu
2
- [![Build Status](https://travis-ci.org/hogelog/ncode-syosetu.svg?branch=master)](https://travis-ci.org/hogelog/ncode-syosetu)
3
- [![Gem Version](https://badge.fury.io/rb/ncode-syosetu.svg)](http://badge.fury.io/rb/ncode-syosetu)
1
+ # Ncode::Syosetu
4
2
 
5
- ncode.syosetu.com content to epub converter.
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ncode/syosetu`. To experiment with that code, run `bin/console` for an interactive prompt.
6
4
 
7
- ## Install
8
- ```
9
- # gem install ncode-syosetu
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ncode-syosetu'
10
13
  ```
11
14
 
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ncode-syosetu
22
+
12
23
  ## Usage
13
- ```
14
- $ ncode2epub.rb n0000aa # http://ncode.syosetu/com/n0000aa -> n0000aa.epub
15
- $ ncode2mobi.rb n0000aa # http://ncode.syosetu/com/n0000aa -> n0000aa.mobi
16
- ```
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ncode-syosetu.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ncode/syosetu"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ require "ncode-syosetu-core"
2
+ require "ncode-syosetu-epub3"
3
+ require "ncode-syosetu-mobi"
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ require_relative '../ncode-syosetu-core/lib/ncode_syosetu/version'
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = "ncode-syosetu"
6
+ spec.version = NcodeSyosetu::VERSION
7
+ spec.authors = ["hogelog"]
8
+ spec.email = ["konbu.komuro@gmail.com"]
9
+
10
+ spec.summary = %q{Ncode syosetu scraper}
11
+ spec.homepage = "https://github.com/hogelog/ncode-syosetu"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
15
+ f.match(%r{^(test|spec|features)/})
16
+ end
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "ncode-syosetu-core", NcodeSyosetu::VERSION
22
+ spec.add_dependency "ncode-syosetu-epub3", NcodeSyosetu::VERSION
23
+ spec.add_dependency "ncode-syosetu-mobi", NcodeSyosetu::VERSION
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.13"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.0"
28
+ spec.add_development_dependency "pry"
29
+ spec.add_development_dependency "webmock"
30
+ end
metadata CHANGED
@@ -1,99 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncode-syosetu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - hogelog
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2015-01-15 00:00:00.000000000 Z
11
+ date: 2017-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: mechanize
14
+ name: ncode-syosetu-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 2.7.2
19
+ version: 0.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 2.7.2
26
+ version: 0.1.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: gepub
28
+ name: ncode-syosetu-epub3
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 0.6.9.2
33
+ version: 0.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 0.6.9.2
40
+ version: 0.1.0
41
41
  - !ruby/object:Gem::Dependency
42
- name: kindlegen
42
+ name: ncode-syosetu-mobi
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
- version: 2.9.0
47
+ version: 0.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
- version: 2.9.0
54
+ version: 0.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.13'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '1.13'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '10.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '10.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '3.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '3.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -108,34 +108,6 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: guard-rspec
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: spring
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
111
  - !ruby/object:Gem::Dependency
140
112
  name: webmock
141
113
  requirement: !ruby/object:Gem::Requirement
@@ -150,26 +122,10 @@ dependencies:
150
122
  - - ">="
151
123
  - !ruby/object:Gem::Version
152
124
  version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: yard
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- description: Ncode syosetu scraper
125
+ description:
168
126
  email:
169
127
  - konbu.komuro@gmail.com
170
- executables:
171
- - ncode2epub.rb
172
- - ncode2mobi.rb
128
+ executables: []
173
129
  extensions: []
174
130
  extra_rdoc_files: []
175
131
  files:
@@ -177,32 +133,13 @@ files:
177
133
  - ".rspec"
178
134
  - ".travis.yml"
179
135
  - Gemfile
180
- - Guardfile
181
136
  - LICENSE.txt
182
137
  - README.md
183
138
  - Rakefile
184
- - bin/ncode2epub.rb
185
- - bin/ncode2mobi.rb
186
- - lib/ncode_syosetu.rb
187
- - lib/ncode_syosetu/builder.rb
188
- - lib/ncode_syosetu/builder/epub3.rb
189
- - lib/ncode_syosetu/builder/mobi.rb
190
- - lib/ncode_syosetu/client.rb
191
- - lib/ncode_syosetu/model.rb
192
- - lib/ncode_syosetu/model/episode.rb
193
- - lib/ncode_syosetu/model/heading.rb
194
- - lib/ncode_syosetu/model/novel.rb
195
- - lib/ncode_syosetu/model/toc.rb
196
- - lib/ncode_syosetu/version.rb
197
- - ncode_syosetu.gemspec
198
- - spec/data/n00000/1.html
199
- - spec/data/n00000/2.html
200
- - spec/data/n00000/index.html
201
- - spec/ncode_syosetu/builder/epub3_spec.rb
202
- - spec/ncode_syosetu/builder/mobi_spec.rb
203
- - spec/ncode_syosetu/client_spec.rb
204
- - spec/spec_helper.rb
205
- - spec/spec_helpers/mock_ncode_data_helper.rb
139
+ - bin/console
140
+ - bin/setup
141
+ - lib/ncode-syosetu.rb
142
+ - ncode-syosetu.gemspec
206
143
  homepage: https://github.com/hogelog/ncode-syosetu
207
144
  licenses:
208
145
  - MIT
@@ -223,17 +160,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
160
  version: '0'
224
161
  requirements: []
225
162
  rubyforge_project:
226
- rubygems_version: 2.4.5
163
+ rubygems_version: 2.5.1
227
164
  signing_key:
228
165
  specification_version: 4
229
166
  summary: Ncode syosetu scraper
230
- test_files:
231
- - spec/data/n00000/1.html
232
- - spec/data/n00000/2.html
233
- - spec/data/n00000/index.html
234
- - spec/ncode_syosetu/builder/epub3_spec.rb
235
- - spec/ncode_syosetu/builder/mobi_spec.rb
236
- - spec/ncode_syosetu/client_spec.rb
237
- - spec/spec_helper.rb
238
- - spec/spec_helpers/mock_ncode_data_helper.rb
239
- has_rdoc:
167
+ test_files: []
data/Guardfile DELETED
@@ -1,6 +0,0 @@
1
- guard :rspec do
2
- watch(%r{^spec/.+_spec\.rb$})
3
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
- watch('spec/spec_helper.rb') { "spec" }
5
- watch(%r{^data/(.+)\.html$}) { "spec" }
6
- end
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
- require 'ncode_syosetu'
5
-
6
- if ARGV.size == 0
7
- puts "ncode2epub.rb ncode [ncode...]"
8
- exit
9
- end
10
-
11
- ARGV.each do |ncode|
12
- novel = NcodeSyosetu.client.get(ncode)
13
- novel.write_epub3("#{ncode}.epub")
14
- end
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
4
- require 'ncode_syosetu'
5
-
6
- if ARGV.size == 0
7
- puts "ncode2mobi.rb ncode [ncode...]"
8
- exit
9
- end
10
-
11
- ARGV.each do |ncode|
12
- novel = NcodeSyosetu.client.get(ncode)
13
- novel.write_mobi("#{ncode}.mobi")
14
- end
@@ -1,12 +0,0 @@
1
- require "ncode_syosetu/version"
2
- require "ncode_syosetu/model"
3
- require "ncode_syosetu/client"
4
- require "ncode_syosetu/builder"
5
-
6
- module NcodeSyosetu
7
- NCODE_HOST_NAME = "ncode.syosetu.com"
8
-
9
- def self.client
10
- @@client ||= Client.new
11
- end
12
- end
@@ -1,7 +0,0 @@
1
- require "ncode_syosetu/builder/epub3"
2
- require "ncode_syosetu/builder/mobi"
3
-
4
- module NcodeSyosetu
5
- module Builder
6
- end
7
- end
@@ -1,53 +0,0 @@
1
- require "tmpdir"
2
- require "gepub"
3
-
4
- module NcodeSyosetu
5
- module Builder
6
- class Epub3
7
- def self.write(novel, path)
8
- Dir.mktmpdir do |tmpdir|
9
- builder = GEPUB::Builder.new do
10
- language "ja"
11
- unique_identifier novel.url
12
- title novel.title
13
- creator novel.author
14
-
15
- date Time.now.to_s
16
-
17
- resources(workdir: tmpdir) do
18
- toc_html = novel.toc.html.gsub(%r[<a href="/[^/]+/(\d+)/?">], '<a href="\1.html">').gsub(/<br>/, '<br />')
19
- File.write("toc.html", toc_html)
20
- nav "toc.html"
21
-
22
- ordered do
23
- next_heading = nil
24
- novel.episodes.each do |episode|
25
- if episode.is_a?(NcodeSyosetu::Model::Heading)
26
- next_heading = episode.title
27
- else
28
- episode_html = episode.html.gsub(/<br>/, '<br />')
29
- html_path = "#{episode.number}.html"
30
- File.write(html_path, episode_html)
31
- file html_path
32
- if next_heading
33
- heading next_heading
34
- next_heading = nil
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
41
-
42
- builder.generate_epub(path)
43
- end
44
- end
45
- end
46
- end
47
-
48
- NcodeSyosetu::Model::Novel.class_eval do
49
- def write_epub3(file)
50
- NcodeSyosetu::Builder::Epub3.write(self, file)
51
- end
52
- end
53
- end
@@ -1,28 +0,0 @@
1
- require "kindlegen"
2
- require "tempfile"
3
-
4
- module NcodeSyosetu
5
- module Builder
6
- class Mobi
7
- def self.write(novel, mobi_path)
8
- mobi_pathname = Pathname.new(mobi_path)
9
- mobi_basename = mobi_pathname.basename.to_s
10
- Dir.mktmpdir do |tmpdir|
11
- epub_path = File.join(tmpdir, "#{mobi_basename}.epub")
12
- NcodeSyosetu::Builder::Epub3.write(novel, epub_path)
13
- STDERR.puts Kindlegen.run(epub_path,
14
- "-verbose",
15
- "-locale", "ja",
16
- "-o", mobi_basename)
17
- File.rename(File.join(tmpdir, mobi_basename), mobi_path)
18
- end
19
- end
20
- end
21
- end
22
-
23
- NcodeSyosetu::Model::Novel.class_eval do
24
- def write_mobi(file)
25
- NcodeSyosetu::Builder::Mobi.write(self, file)
26
- end
27
- end
28
- end
@@ -1,60 +0,0 @@
1
- require 'mechanize'
2
- require "logger"
3
-
4
- module NcodeSyosetu
5
- class Client
6
- class NotFound < StandardError
7
- attr_reader :url
8
-
9
- def initialize(url, error_message = nil)
10
- super(error_message)
11
- @url = url
12
- end
13
- end
14
-
15
- def initialize(logger: Logger.new(STDOUT), sleep: 0.5)
16
- @mechanize = Mechanize.new
17
- @logger = logger
18
- @sleep = sleep
19
- end
20
-
21
- def get(ncode)
22
- toc = get_toc(ncode)
23
-
24
- episodes = toc.episodes.map do |episode|
25
- if episode[:number]
26
- get_episode(ncode, episode[:text], episode[:number])
27
- else
28
- NcodeSyosetu::Model::Heading.new(episode[:text])
29
- end
30
- end
31
-
32
- NcodeSyosetu::Model::Novel.new(toc, episodes)
33
- end
34
-
35
- def get_toc(ncode)
36
- url = toc_url(ncode)
37
- NcodeSyosetu::Model::Toc.new(get_content(toc_url(ncode)))
38
- end
39
-
40
- def get_episode(ncode, title, number)
41
- sleep(@sleep)
42
- NcodeSyosetu::Model::Episode.new(title, number, get_content(episode_url(ncode, number)))
43
- end
44
-
45
- def toc_url(ncode)
46
- "http://#{NcodeSyosetu::NCODE_HOST_NAME}/#{ncode}"
47
- end
48
-
49
- def episode_url(ncode, number)
50
- "http://#{NcodeSyosetu::NCODE_HOST_NAME}/#{ncode}/#{number}"
51
- end
52
-
53
- private
54
-
55
- def get_content(url)
56
- @logger.info("GET #{url}...")
57
- @mechanize.get(url)
58
- end
59
- end
60
- end
@@ -1,9 +0,0 @@
1
- require "ncode_syosetu/model/novel"
2
- require "ncode_syosetu/model/toc"
3
- require "ncode_syosetu/model/heading"
4
- require "ncode_syosetu/model/episode"
5
-
6
- module NcodeSyosetu
7
- module Model
8
- end
9
- end
@@ -1,37 +0,0 @@
1
- require "erb"
2
-
3
- module NcodeSyosetu
4
- module Model
5
- class Episode
6
- attr_accessor :title, :number, :body_html, :url
7
-
8
- def initialize(title, number, page)
9
- @url = page.uri.to_s
10
- @title = title
11
- @number = number
12
-
13
- @body_html =
14
- page.search(".novel_subtitle").to_html <<
15
- page.search(".novel_view").to_html
16
- end
17
-
18
- def html
19
- <<-HTML
20
- <?xml version="1.0" encoding="UTF-8"?>
21
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
22
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
23
- <head>
24
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
25
- <title>#{@title}</title>
26
- </head>
27
- <body>
28
-
29
- #{@body_html}
30
-
31
- </body>
32
- </html>
33
- HTML
34
- end
35
- end
36
- end
37
- end
@@ -1,11 +0,0 @@
1
- module NcodeSyosetu
2
- module Model
3
- class Heading
4
- attr_accessor :title
5
-
6
- def initialize(title)
7
- @title = title
8
- end
9
- end
10
- end
11
- end
@@ -1,20 +0,0 @@
1
- module NcodeSyosetu
2
- module Model
3
- class Novel
4
- attr_accessor :toc, :episodes
5
-
6
- def initialize(toc, episodes)
7
- @toc = toc
8
- @episodes = episodes
9
- end
10
-
11
- [:title, :author, :abstract, :url].each do |method|
12
- class_eval <<-EOS
13
- def #{method}
14
- @toc.#{method}
15
- end
16
- EOS
17
- end
18
- end
19
- end
20
- end
@@ -1,50 +0,0 @@
1
- module NcodeSyosetu
2
- module Model
3
- class Toc
4
- attr_accessor :title, :author, :abstract, :url, :episodes
5
-
6
- def initialize(page)
7
- @url = page.uri.to_s
8
- @title = page.title
9
- @author = page.search(".novel_writername").text.chomp
10
- @abstract = page.search(".novel_ex").text.chomp
11
-
12
- @episodes = []
13
- page.at(".index_box").children.each do |sub_item|
14
- next unless sub_item.matches?('.chapter_title, .novel_sublist2')
15
- episode = { text: sub_item.text.gsub(/\s+/, " ").chomp }
16
- link = sub_item.search("a")
17
- unless link.empty?
18
- if link.attr("href").value =~ %r[/(\d+)/?$]
19
- episode[:number] = $1.to_i
20
- end
21
- end
22
- @episodes << episode
23
- end
24
-
25
- @body_html =
26
- page.search(".novel_writername").to_html <<
27
- page.search(".novel_ex").to_html <<
28
- page.search(".index_box").to_html
29
- end
30
-
31
- def html
32
- <<-HTML
33
- <?xml version="1.0" encoding="UTF-8"?>
34
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
35
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
36
- <head>
37
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
38
- <title>#{@title}</title>
39
- </head>
40
- <body>
41
-
42
- #{@body_html}
43
-
44
- </body>
45
- </html>
46
- HTML
47
- end
48
- end
49
- end
50
- end
@@ -1,3 +0,0 @@
1
- module NcodeSyosetu
2
- VERSION = "0.0.7"
3
- end
@@ -1,33 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'ncode_syosetu/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "ncode-syosetu"
8
- spec.version = NcodeSyosetu::VERSION
9
- spec.authors = ["hogelog"]
10
- spec.email = ["konbu.komuro@gmail.com"]
11
- spec.description = %q{Ncode syosetu scraper}
12
- spec.summary = %q{Ncode syosetu scraper}
13
- spec.homepage = "https://github.com/hogelog/ncode-syosetu"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_dependency "mechanize", "2.7.2"
22
- spec.add_dependency "gepub", "0.6.9.2"
23
- spec.add_dependency "kindlegen", "~> 2.9.0"
24
-
25
- spec.add_development_dependency "bundler"
26
- spec.add_development_dependency "rake"
27
- spec.add_development_dependency "rspec"
28
- spec.add_development_dependency "pry"
29
- spec.add_development_dependency "guard-rspec"
30
- spec.add_development_dependency "spring"
31
- spec.add_development_dependency "webmock"
32
- spec.add_development_dependency "yard"
33
- end
@@ -1,17 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
- <title>たいとる</title>
7
- </head>
8
- <body>
9
-
10
- <div class="novel_subtitle"><div class="chapter_title">第1章</div>第一話</div>
11
- <div class="novel_view" id="novel_view">
12
-  本文<br />
13
-  <ruby><rb>漢字</rb><rt>かんじ</rt></ruby>
14
- </div>
15
-
16
- </body>
17
- </html>
@@ -1,17 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
- <title>たいとる</title>
7
- </head>
8
- <body>
9
-
10
- <div class="novel_subtitle"><div class="chapter_title">第1章</div>第一話</div>
11
- <div class="novel_view" id="novel_view">
12
-  本文<br />
13
-  <ruby><rb>漢字</rb><rt>かんじ</rt></ruby>
14
- </div>
15
-
16
- </body>
17
- </html>
@@ -1,26 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
4
- <head>
5
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
- <title>たいとる</title>
7
- </head>
8
- <body>
9
-
10
- <div class="novel_writername">作者:<a href="http://mypage.syosetu.com/00000/">さくしゃ</a></div>
11
- <div class="novel_ex">あらすじ</div>
12
- <div class="index_box">
13
- <div class="chapter_title">第1章</div>
14
- <dl class="novel_sublist2">
15
- <dd class="subtitle"><a href="/n00000/1/">第一話</a></dd>
16
- <dt class="long_update">2014年 1月 31日</dt>
17
- </dl>
18
- <div class="chapter_title">第2章</div>
19
- <dl class="novel_sublist2">
20
- <dd class="subtitle"><a href="/n00000/2/">第二話</a></dd>
21
- <dt class="long_update">2014年 2月 31日</dt>
22
- </dl>
23
- </div>
24
-
25
- </body>
26
- </html>
@@ -1,18 +0,0 @@
1
- require "spec_helper"
2
- require "spec_helpers/mock_ncode_data_helper"
3
- require "tempfile"
4
-
5
- describe NcodeSyosetu::Builder::Epub3 do
6
- include_context "with mock ncode data"
7
-
8
- let(:ncode) { "n00000" }
9
- let(:novel) { NcodeSyosetu.client.get(ncode) }
10
-
11
- describe ".write" do
12
- it "writes epub3" do
13
- Tempfile.open("epub3") do |file|
14
- NcodeSyosetu::Builder::Epub3.write(novel, file.path)
15
- end
16
- end
17
- end
18
- end
@@ -1,18 +0,0 @@
1
- require "spec_helper"
2
- require "spec_helpers/mock_ncode_data_helper"
3
- require "tempfile"
4
-
5
- describe NcodeSyosetu::Builder::Epub3 do
6
- include_context "with mock ncode data"
7
-
8
- let(:ncode) { "n00000" }
9
- let(:novel) { NcodeSyosetu.client.get(ncode) }
10
-
11
- describe ".write" do
12
- it "writes mobi" do
13
- Tempfile.open("mobi") do |file|
14
- NcodeSyosetu::Builder::Mobi.write(novel, file.path)
15
- end
16
- end
17
- end
18
- end
@@ -1,23 +0,0 @@
1
- require "spec_helper"
2
- require "spec_helpers/mock_ncode_data_helper"
3
-
4
- describe NcodeSyosetu::Client do
5
- include_context "with mock ncode data"
6
-
7
- let(:ncode) { "n00000" }
8
-
9
- describe "#get" do
10
- subject { NcodeSyosetu.client.get(ncode) }
11
-
12
- it "scrapes ncode novel" do
13
- expect(subject.toc.title).to eq("たいとる")
14
- expect(subject.episodes.size).to eq(4)
15
- expect(subject.episodes[0]).to be_a(NcodeSyosetu::Model::Heading)
16
- expect(subject.episodes[1]).to be_a(NcodeSyosetu::Model::Episode)
17
- expect(subject.episodes[1].number).to eq(1)
18
- expect(subject.episodes[2]).to be_a(NcodeSyosetu::Model::Heading)
19
- expect(subject.episodes[3]).to be_a(NcodeSyosetu::Model::Episode)
20
- expect(subject.episodes[3].number).to eq(2)
21
- end
22
- end
23
- end
@@ -1,4 +0,0 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
- require 'ncode_syosetu'
3
- require 'pry'
4
- require 'webmock/rspec'
@@ -1,22 +0,0 @@
1
- require 'webmock/rspec'
2
- require 'yard'
3
-
4
- DATA_DIR = File.expand_path('../../data', __FILE__)
5
-
6
- shared_context "with mock ncode data" do
7
- before do
8
- Dir.glob("#{DATA_DIR}/*").each do |ncode_dir|
9
- ncode = File.relative_path(DATA_DIR, ncode_dir)
10
- Dir.glob("#{ncode_dir}/*").each do |html_path|
11
- File.relative_path(ncode_dir, html_path)
12
- if html_path.end_with?("index.html")
13
- path = "#{ncode}"
14
- elsif html_path =~ /(\d+).html$/
15
- path = "#{ncode}/#{$1}"
16
- end
17
- WebMock.stub_request(:get, "http://#{NcodeSyosetu::NCODE_HOST_NAME}/#{path}").
18
- to_return(body: File.new(html_path), status: 200, headers: { 'Content-Type' => 'text/html' })
19
- end
20
- end
21
- end
22
- end