telegraph-parser 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/telegraph/parser/article.rb +1 -1
- data/lib/telegraph/parser/formats/format.rb +38 -0
- data/lib/telegraph/parser/formats/html.rb +58 -0
- data/lib/telegraph/parser/formats/markdown.rb +25 -0
- data/lib/telegraph/parser/formats.rb +10 -0
- data/lib/telegraph/parser/version.rb +1 -1
- data/lib/telegraph/parser.rb +1 -0
- data/telegraph-parser.gemspec +2 -0
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc87395f219d7f4409546a189650963ce8e1267b
|
4
|
+
data.tar.gz: 9f43be8de7e80dbf1655891995ac23b70754e90d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 431c9bdaca65f2bfda1e0acc8d82cd0e872d05ef73819e770bb5841d4dd8136dd34b3bd600077f8aa95c2c8d6cbc78d265f7ce62450bd675b2028c00e3ec6dd2
|
7
|
+
data.tar.gz: 2a1265c39454c43b7cf1f9b611c4492e3b2ac61996c2056e9ae22235fbc15ad4367de262273865490502217d9a2c62f0b412b4961da75dce87bac828c2070a45
|
data/.gitignore
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
module Telegraph
|
2
|
+
module Parser
|
3
|
+
module Formats
|
4
|
+
class Format
|
5
|
+
attr_reader :content
|
6
|
+
|
7
|
+
def self.find(article_id, options={})
|
8
|
+
article = Telegraph::Parser::Article.find(article_id)
|
9
|
+
new(article, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(article, options = {})
|
13
|
+
@article = article
|
14
|
+
@options = options
|
15
|
+
@content = ""
|
16
|
+
end
|
17
|
+
|
18
|
+
def process!
|
19
|
+
raise 'Not implemented yet'
|
20
|
+
end
|
21
|
+
|
22
|
+
def save(destination)
|
23
|
+
FileUtils.mkdir_p(destination)
|
24
|
+
|
25
|
+
File.open("#{destination}/#{filename}", "w") do |f|
|
26
|
+
f.write(@content)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def filename
|
33
|
+
raise 'Not implemented yet'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Telegraph
|
2
|
+
module Parser
|
3
|
+
module Formats
|
4
|
+
class Html < Format
|
5
|
+
def process!
|
6
|
+
build_content
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_content
|
10
|
+
@content = <<-HTML.strip
|
11
|
+
<html>
|
12
|
+
<head>
|
13
|
+
<meta charset="UTF-8">
|
14
|
+
<title>#{@article.title}</title>
|
15
|
+
</head>
|
16
|
+
|
17
|
+
<body>
|
18
|
+
<h1>
|
19
|
+
#{@article.title}
|
20
|
+
<small>#{@article.author}</small>
|
21
|
+
</h1>
|
22
|
+
|
23
|
+
<div>
|
24
|
+
#{@article.content}
|
25
|
+
</div>
|
26
|
+
</body>
|
27
|
+
</html>
|
28
|
+
HTML
|
29
|
+
end
|
30
|
+
|
31
|
+
def save(destination)
|
32
|
+
super
|
33
|
+
|
34
|
+
@article.images.each do |path, image|
|
35
|
+
ensure_path_exists(destination, path)
|
36
|
+
|
37
|
+
File.open("#{destination}#{path}", 'wb') do |f|
|
38
|
+
f.write(image)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
true
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
|
47
|
+
def filename
|
48
|
+
"#{@article.title}.html"
|
49
|
+
end
|
50
|
+
|
51
|
+
def ensure_path_exists(destination, path)
|
52
|
+
dir_seg = File.dirname("#{destination}#{path}")
|
53
|
+
FileUtils.mkdir_p(dir_seg)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'html2markdown'
|
2
|
+
|
3
|
+
module Telegraph
|
4
|
+
module Parser
|
5
|
+
module Formats
|
6
|
+
class Markdown < Html
|
7
|
+
def process!
|
8
|
+
build_content
|
9
|
+
convert_to_md
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def convert_to_md
|
15
|
+
@content = HTMLPage.new(contents: @content).markdown
|
16
|
+
end
|
17
|
+
|
18
|
+
def filename
|
19
|
+
"#{@article.title}.md"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/telegraph/parser.rb
CHANGED
data/telegraph-parser.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
+
spec.add_dependency "html2markdown"
|
22
|
+
|
21
23
|
spec.add_development_dependency "bundler", "~> 1.11"
|
22
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
23
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: telegraph-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Vernidub
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: html2markdown
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,6 +114,10 @@ files:
|
|
100
114
|
- lib/telegraph/parser/article.rb
|
101
115
|
- lib/telegraph/parser/errors.rb
|
102
116
|
- lib/telegraph/parser/fetcher.rb
|
117
|
+
- lib/telegraph/parser/formats.rb
|
118
|
+
- lib/telegraph/parser/formats/format.rb
|
119
|
+
- lib/telegraph/parser/formats/html.rb
|
120
|
+
- lib/telegraph/parser/formats/markdown.rb
|
103
121
|
- lib/telegraph/parser/parser.rb
|
104
122
|
- lib/telegraph/parser/version.rb
|
105
123
|
- telegraph-parser.gemspec
|