Class: TxtBook
Overview
文本书籍
文本书籍现状
解决办法
问题1: 不包含目录结构
问题2: 包含目录结构,同时列出目录
问题3: 目录结构信息是以节等组成
Constant Summary
Constants included from HeaderDetect
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#isbn ⇒ Object
readonly
Returns the value of attribute isbn.
-
#pubdate ⇒ Object
readonly
Returns the value of attribute pubdate.
-
#publisher ⇒ Object
readonly
Returns the value of attribute publisher.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #breaklines ⇒ Object
- #breaklines_count ⇒ Object
-
#initialize(content, options = {}) ⇒ TxtBook
constructor
A new instance of TxtBook.
- #struct_content ⇒ Object
- #to_doc_book ⇒ Object
- #toc ⇒ Object
- #toc_to_text ⇒ Object
Methods included from HeaderDetect
#guess_appendix?, #guess_chapter?, #guess_digital_header?, #guess_digital_section?, #guess_glossary?, #guess_header?, #guess_index?, #guess_part?, #guess_preface?, #guess_section?, #guess_volume?, #hav_complete_sentence?, #valid_title?
Constructor Details
#initialize(content, options = {}) ⇒ TxtBook
Returns a new instance of TxtBook.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/txt_book.rb', line 56 def initialize(content,={}) @title = [:title] = [:author] @publisher = [:publisher] @pubdate= [:pubdate] @isbn = [:isbn] @format = [:format] unless Utils.detect_utf8(content) content = Utils.to_utf8(content) end @content = preprocess_content(content) end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
47 48 49 |
# File 'lib/txt_book.rb', line 47 def end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
47 48 49 |
# File 'lib/txt_book.rb', line 47 def content @content end |
#isbn ⇒ Object (readonly)
Returns the value of attribute isbn.
47 48 49 |
# File 'lib/txt_book.rb', line 47 def isbn @isbn end |
#pubdate ⇒ Object (readonly)
Returns the value of attribute pubdate.
47 48 49 |
# File 'lib/txt_book.rb', line 47 def pubdate @pubdate end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
47 48 49 |
# File 'lib/txt_book.rb', line 47 def publisher @publisher end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
47 48 49 |
# File 'lib/txt_book.rb', line 47 def title @title end |
Class Method Details
.load(filename, options = {}) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/txt_book.rb', line 49 def self.load(filename,={}) raise '无效的文件' unless File.exists?(filename) [:title] = File.basename(filename, File.extname(filename)) content = File.open(filename).read new(content,) end |
Instance Method Details
#breaklines ⇒ Object
81 82 83 |
# File 'lib/txt_book.rb', line 81 def breaklines @breaklines ||= Utils.breaklines(content) end |
#breaklines_count ⇒ Object
85 86 87 |
# File 'lib/txt_book.rb', line 85 def breaklines_count breaklines.count end |
#struct_content ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/txt_book.rb', line 71 def struct_content return @struct_content if @struct_content content = if breaklines_count > 100 Utils.fixed_page_break(@content) else @content end @struct_content = extract_book_struct(content,:format=>@format) end |
#to_doc_book ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/txt_book.rb', line 101 def to_doc_book if struct_content build_doc_book(struct_content,{:title=>title,:publisher=>publisher,:pubdate=>pubdate,:author=>,:isbn=>isbn}) else build_doc_book(content,{:title=>title,:publisher=>publisher,:pubdate=>pubdate,:author=>,:isbn=>isbn}) end end |
#toc ⇒ Object
89 90 91 |
# File 'lib/txt_book.rb', line 89 def toc @toc ||= extract_toc_from_struct(struct_content) if struct_content end |
#toc_to_text ⇒ Object
93 94 95 96 97 98 99 |
# File 'lib/txt_book.rb', line 93 def toc_to_text if toc gen_toc(toc) do |item,children| "#{item[:title]}\n#{children}" end end end |