Sha256: bc9bd8232642a5bbafa0a7aad2ce9164bc0b7fcedad113192ddbf24568171bf5

Contents?: true

Size: 1.37 KB

Versions: 9

Compression:

Stored size: 1.37 KB

Contents

module NcodeSyosetu
  module Model
    class Toc
      attr_accessor :title, :author, :abstract, :url, :episodes

      def initialize(page)
        @url = page.uri.to_s
        @title = page.title
        @author = page.search(".novel_writername").text.chomp
        @abstract = page.search(".novel_ex").text.chomp

        @episodes = []
        page.at(".index_box").children.each do |sub_item|
          next unless sub_item.matches?('.chapter_title, .novel_sublist2')
          episode = { text: sub_item.text.gsub(/\s+/, " ").chomp }
          link = sub_item.search("a")
          unless link.empty?
            if link.attr("href").value =~ %r[/(\d+)/?$]
              episode[:number] = $1.to_i
            end
          end
          @episodes << episode
        end

        @body_html =
          page.search(".novel_writername").to_html <<
          page.search(".novel_ex").to_html <<
          page.search(".index_box").to_html
      end

      def html
        <<-HTML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>#{@title}</title>
</head>
<body>

#{@body_html}

</body>
</html>
        HTML
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
ncode-syosetu-core-0.2.3 lib/ncode_syosetu/model/toc.rb
ncode-syosetu-core-0.2.2 lib/ncode_syosetu/model/toc.rb
ncode-syosetu-core-0.2.1 lib/ncode_syosetu/model/toc.rb
ncode-syosetu-core-0.2.0 lib/ncode_syosetu/model/toc.rb
ncode-syosetu-core-0.1.2 lib/ncode_syosetu/model/toc.rb
ncode-syosetu-core-0.1.1 lib/ncode_syosetu/model/toc.rb
ncode-syosetu-core-0.1.0 lib/ncode_syosetu/model/toc.rb
ncode-syosetu-0.0.7 lib/ncode_syosetu/model/toc.rb
ncode-syosetu-0.0.6 lib/ncode_syosetu/model/toc.rb