colread 0.0.0 → 0.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/colread.rb +11 -2
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20aa61c77b99f49fd87290fe5061307ebd517d83
4
- data.tar.gz: 103f1857d93809b17a6f2d850033555c3061bc41
3
+ metadata.gz: a5110d542174b574c2684dcfbeca7cad9fc7ecc6
4
+ data.tar.gz: 1d2ffdab33b442c885ff8150c3256b08c1dd0f35
5
5
  SHA512:
6
- metadata.gz: ea3687991d2e945d896e8069ad7a85df8e7e0f68bd50662139f7ea073bcfc7c28387b88c3121e7a98f54a9b857d35b2653af6690d1947aa7b305ae37fd8721b4
7
- data.tar.gz: b070e16493c92b5b90f24c4013561fe85aaa442c7974e883ae3bd29ed13facf835f00a5b5cb9d83531803c627466faddcb5bc6b495c416b7e84d02611bed0095
6
+ metadata.gz: 41f05aff1a11775039a4cd4baea4aee38af87ca5ca71ff95f8b04deb773bfeec6e1396659e4066be2fae0ccebc74c66d2e4ec1a849a44830780a1a1ed0e6dabf
7
+ data.tar.gz: 80f1e2405b4c100464758550fe5d82105024efcdb9dd0e20e2ab0a9d66f6c8b875ee3fe31175983145cf7bdfa40ef571a0f233d31468fed35689c8b64aae9a3b
data/lib/colread.rb CHANGED
@@ -19,10 +19,19 @@ module ColRead
19
19
  doc.css('a').group_by{|a| a.indent}.sort_by{|a| a.last.count}.last.last
20
20
  end
21
21
 
22
+ def ahref a
23
+ if a['href'].start_with?('http')
24
+ a['href']
25
+ elsif a['href'].start_with?('/')
26
+ @root+a['href']
27
+ else
28
+ @url.sub(/\/(index.\w+)?$/, '') + '/' + a['href']
29
+ end
30
+ end
31
+
22
32
  def contents chapters
23
33
  chapters.each do |a|
24
- href=a['href'].start_with?('http') ? a['href'] : @root+a['href']
25
- source = open(href).read.encode('utf-8')
34
+ source = open(ahref(a)).read.encode('utf-8')
26
35
  content=Nokogiri::HTML(Readability::Document.new(source).content).text
27
36
  yield [a.text, content]
28
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colread
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - yunjie chen