Class: Aozoragen::SaiZenSen

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/aozoragen/sai-zen-sen.rb

Instance Method Summary collapse

Methods included from Util

#detag

Constructor Details

#initialize(index_uri) ⇒ SaiZenSen

Returns a new instance of SaiZenSen.



13
14
15
16
17
18
19
20
21
22
# File 'lib/aozoragen/sai-zen-sen.rb', line 13

def initialize( index_uri )
	case index_uri.path
	when '/sa/fate-zero/works/'
		@entity = SaiZenSenFateZero::new( index_uri )
	when %r|/01.html$| # short story
		@entity = SaiZenSenShort::new( index_uri )
	else
		@entity = SaiZenSenRegular::new( index_uri )
	end
end

Instance Method Details

#each_chapterObject



28
29
30
31
32
33
# File 'lib/aozoragen/sai-zen-sen.rb', line 28

def each_chapter
	@entity.each_chapter do |c|
		c[:text] = c[:text].normalize_char.han2zen.for_tategaki
		yield c
	end
end

#each_chapter_local(selector) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/aozoragen/sai-zen-sen.rb', line 35

def each_chapter_local( selector )
	(@index_html / selector).each do |a|
		uri = @index_uri + a.attr('href')
		next if uri.path == '/entryguide.html' # skipping member only contents.

		chapter = Nokogiri( open( uri, 'r:utf-8', &:read ) )
		text = get_chapter_text( chapter )
		yield( {id: Pathname( uri.path ).dirname.basename.to_s, uri: uri, text: text} )
	end
end

#get_chapter_text(chapter) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/aozoragen/sai-zen-sen.rb', line 46

def get_chapter_text( chapter )
	text = ''
	(chapter / 'section.book-page-spread').each do |page|
		page.children.each do |section|
			case section.name
			when 'hgroup'
				text << detag( section ).subhead
			when 'div'
				case section.attr( 'class' )
				when /delimiter/
					text << "[#5字下げ]#{'' * 10}\n\n"
				when /pgroup/
					(section / 'p').each do |paragraph|
						text << " #{detag paragraph}\n"
					end
					text << "\n"
				else
					(section / 'div.pgroup').each do |div|
						(div / 'p').each do |paragraph|
							text << " #{detag paragraph}\n"
						end
						text << "\n"
					end
				end
			end
		end
		text << "[#改ページ]\n"
	end
	text
end

#metainfoObject



24
25
26
# File 'lib/aozoragen/sai-zen-sen.rb', line 24

def metainfo
	@entity.metainfo
end