aozoragen 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.version = Aozoragen::VERSION
8
8
  s.authors = ["TADA Tadashi"]
9
9
  s.email = ["t@tdtds.jp"]
10
- s.homepage = ""
10
+ s.homepage = "https://github.com/tdtds/aozoragen"
11
11
  s.summary = "Generating AOZORA format text of eBook novels via some Web sites."
12
12
  s.description = "Scraping some Ebook web site and generating AOZORA format text files."
13
13
 
@@ -16,5 +16,5 @@ require 'cgi'
16
16
 
17
17
  uri = URI( 'http://a2k.aill.org/download.cgi' )
18
18
  text = ARGF.read.force_encoding( 'UTF-8' )
19
- res = Net::HTTP.post_form( uri, 's' => 's', 'text' => text )
19
+ res = Net::HTTP.post_form( uri, 's' => 'm', 'text' => text )
20
20
  print res.body
@@ -48,5 +48,6 @@ class Renzaburo
48
48
  end
49
49
  end
50
50
  text << "[#改ページ]\n"
51
+ text.gsub( /</, '〈' ).gsub( />/, '〉' )
51
52
  end
52
53
  end
@@ -8,21 +8,23 @@ require 'pathname'
8
8
 
9
9
  class SaiZenSen
10
10
  def initialize( index_uri )
11
- @index_uri = index_uri
12
- @index_html = Nokogiri( open( @index_uri, 'r:utf-8', &:read ) )
11
+ if index_uri.path == '/sa/fate-zero/works/'
12
+ @entity = SaiZenSenFateZero::new( index_uri )
13
+ else
14
+ @entity = SaiZenSenRegular::new( index_uri )
15
+ end
13
16
  end
14
17
 
15
18
  def metainfo
16
- info = {:id => Pathname( @index_uri.path ).basename.to_s}
17
- info[:title] = (@index_html / '#page-content-heading h1')[0].text
18
- (@index_html / '#authors h3').each do |author|
19
- info[:author] = (info[:author] || [] ) << author.text.sub( /.*? /, '' )
20
- end
21
- info
19
+ @entity.metainfo
22
20
  end
23
21
 
24
22
  def each_chapter
25
- (@index_html / '#back-numbers li a').each do |a|
23
+ @entity.each_chapter{|c| yield c}
24
+ end
25
+
26
+ def each_chapter_local( selector )
27
+ (@index_html / selector).each do |a|
26
28
  uri = @index_uri + a.attr('href')
27
29
  chapter = Nokogiri( open( uri, 'r:utf-8', &:read ) )
28
30
  text = ''
@@ -69,3 +71,44 @@ class SaiZenSen
69
71
  elem.to_html.gsub( /<.*?>/, '' ).strip
70
72
  end
71
73
  end
74
+
75
+ class SaiZenSenRegular < SaiZenSen
76
+ def initialize( index_uri )
77
+ @index_uri = index_uri
78
+ @index_html = Nokogiri( open( @index_uri, 'r:utf-8', &:read ) )
79
+ end
80
+
81
+ def metainfo
82
+ info = {:id => Pathname( @index_uri.path ).basename.to_s, :author => []}
83
+ info[:title] = (@index_html / '#page-content-heading h1')[0].text
84
+ (@index_html / '#authors h3').each do |author|
85
+ info[:author] << author.text.sub( /.*? /, '' )
86
+ end
87
+ info
88
+ end
89
+
90
+ def each_chapter
91
+ each_chapter_local( '#back-numbers li a' ){|c| yield c}
92
+ end
93
+ end
94
+
95
+ class SaiZenSenFateZero < SaiZenSen
96
+ def initialize( index_uri )
97
+ @index_uri = index_uri
98
+ @index_html = Nokogiri( open( @index_uri, 'r:utf-8', &:read ) )
99
+ end
100
+
101
+ def metainfo
102
+ info = {
103
+ :id => Pathname( @index_uri.path ).basename.to_s,
104
+ :author => ['虚淵玄']
105
+ }
106
+ info[:title] = (@index_html / 'h1 img')[0].attr( 'alt' )
107
+ info
108
+ end
109
+
110
+ def each_chapter
111
+ each_chapter_local( 'article a' ){|c| yield c}
112
+ end
113
+
114
+ end
@@ -1,3 +1,3 @@
1
1
  module Aozoragen
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
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.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-23 00:00:00.000000000 Z
12
+ date: 2012-02-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &74650980 !ruby/object:Gem::Requirement
16
+ requirement: &85482890 !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: *74650980
24
+ version_requirements: *85482890
25
25
  description: Scraping some Ebook web site and generating AOZORA format text files.
26
26
  email:
27
27
  - t@tdtds.jp
@@ -42,7 +42,7 @@ files:
42
42
  - lib/aozoragen/renzaburo.rb
43
43
  - lib/aozoragen/sai-zen-sen.rb
44
44
  - lib/aozoragen/version.rb
45
- homepage: ''
45
+ homepage: https://github.com/tdtds/aozoragen
46
46
  licenses: []
47
47
  post_install_message:
48
48
  rdoc_options: []