aozoragen 0.0.2 → 0.0.3

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.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Aozoragen
2
+ Web上の小説を青空文庫形式のテキストにする。
3
+
4
+ ## How to install
5
+ Gemを使ってインストールする:
6
+
7
+ gem install aozoragen
8
+
9
+ ## Command-line syntax
10
+ ### aozoragen
11
+ 指定されたWebサイトをスクレイピングして、青空文庫形式のテキストファイルを生成する。
12
+
13
+ % aozoragen <URL>
14
+
15
+ `URL`には日本語の小説をHTML形式で配布しているサイトの目次ページを指定する。カレントディレクトリに章ごとのテキストファイル(拡張子.txt)を生成する。ファイル名はサイトごとに自動的に決定され、`hoge.NN.txt` (NNは数値)のような形式となる。これらのファイルを連結すると一冊の本になる。
16
+
17
+ `aozoragen`コマンドが現在対応しているのは以下のサイト:
18
+
19
+ * 最前線 <http://sai-zen-sen.jp/>
20
+ * 指定例: http://sai-zen-sen.jp/fictions/marginaloperation/
21
+ * 実行時に無償公開中の章のみが抽出される。
22
+ * レンザブロー <http://renzaburo.jp/>
23
+ * 指定例: http://renzaburo.jp/contents_t/061-katano/index.html
24
+
25
+ ### aozora2pdf
26
+ [青空キンドル](http://a2k.aill.org/)を使ってテキストをKindle向けPDFにする。パラメタにはaozoragenで生成した青空文庫形式のテキストファイルを順番通りに指定する。PDFは標準出力に出るので、リダイレクトする:
27
+
28
+ % aozora2pdf hoge*.txt > hoge.pdf
29
+
30
+ ## 注意
31
+ Web上に公開されている小説は著作権の保護下にある。ダウンロードしたテキストは個人の利用のみにとどめ、決して再配布・公衆送信などをしてはいけない。読みやすく加工しやすいHTML形式で小説を公開してくれている各サービスおよび著者の方々に感謝を。
@@ -27,20 +27,27 @@ class SaiZenSen
27
27
  chapter = Nokogiri( open( uri, 'r:utf-8', &:read ) )
28
28
  text = ''
29
29
  (chapter / 'section.book-page-spread').each do |page|
30
- page./( 'hgroup', 'div.pgroup' ).each do |section|
30
+ page.children.each do |section|
31
31
  case section.name
32
32
  when 'hgroup'
33
33
  text << "\n     #{detag section}\n\n"
34
34
  when 'div'
35
- if section.attr( 'class' ) =~ /delimiter/
36
- text << ' ' * 5 << '─' * 10 << "\n"
37
- else
38
- section.children.each do |paragraph|
39
- next unless paragraph.name == 'p'
35
+ case section.attr( 'class' )
36
+ when /delimiter/
37
+ text << ' ' * 5 << '─' * 10 << "\n\n"
38
+ when /pgroup/
39
+ (section / 'p').each do |paragraph|
40
40
  text << " #{detag paragraph}\n"
41
41
  end
42
+ text << "\n"
43
+ else
44
+ (section / 'div.pgroup').each do |div|
45
+ (div / 'p').each do |paragraph|
46
+ text << " #{detag paragraph}\n"
47
+ end
48
+ text << "\n"
49
+ end
42
50
  end
43
- text << "\n"
44
51
  end
45
52
  end
46
53
  text << "[#改ページ]\n"
@@ -1,3 +1,3 @@
1
1
  module Aozoragen
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aozoragen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &78022280 !ruby/object:Gem::Requirement
16
+ requirement: &74650980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *78022280
24
+ version_requirements: *74650980
25
25
  description: Scraping some Ebook web site and generating AOZORA format text files.
26
26
  email:
27
27
  - t@tdtds.jp
@@ -33,6 +33,7 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - .gitignore
35
35
  - Gemfile
36
+ - README.md
36
37
  - Rakefile
37
38
  - aozoragen.gemspec
38
39
  - bin/aozora2pdf