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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26cc01f88e7399f22fa4289fbb7d48dd9abb1e42
4
- data.tar.gz: 3396ed38a2844d8daf0512107246e2f9cb07fa37
3
+ metadata.gz: bc87395f219d7f4409546a189650963ce8e1267b
4
+ data.tar.gz: 9f43be8de7e80dbf1655891995ac23b70754e90d
5
5
  SHA512:
6
- metadata.gz: 9275b8c5a759ab28c47dc4d0da3968ba965c9a5bcb8684dbbb7bac626013b348b6649597b57373958d5d9d3a52a59c4f62e1af5b6f2b19455cd16e6b18e0ebe0
7
- data.tar.gz: 51ba6f30a59614dcd26670c101bd059b4a6f6655c985fc7b0eaa261c2350be350a5259caa75a29dcfd575d6e9fc7b53c2e272fcce7ede226a946f606486a94a8
6
+ metadata.gz: 431c9bdaca65f2bfda1e0acc8d82cd0e872d05ef73819e770bb5841d4dd8136dd34b3bd600077f8aa95c2c8d6cbc78d265f7ce62450bd675b2028c00e3ec6dd2
7
+ data.tar.gz: 2a1265c39454c43b7cf1f9b611c4492e3b2ac61996c2056e9ae22235fbc15ad4367de262273865490502217d9a2c62f0b412b4961da75dce87bac828c2070a45
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .DS_Store
11
+ *.gem
@@ -5,7 +5,7 @@ module Telegraph
5
5
 
6
6
  attr_reader *ATTRIBUTES
7
7
 
8
- def initialize(attributes)
8
+ def initialize(attributes, image_prefix: '')
9
9
  attributes.each do |attr, val|
10
10
  next unless ATTRIBUTES.include?(attr.to_sym)
11
11
  instance_variable_set(:"@#{attr}", val)
@@ -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
@@ -0,0 +1,10 @@
1
+ require "telegraph/parser/formats/format"
2
+ require "telegraph/parser/formats/html"
3
+ require "telegraph/parser/formats/markdown"
4
+
5
+ module Telegraph
6
+ module Parser
7
+ module Formats
8
+ end
9
+ end
10
+ end
@@ -1,5 +1,5 @@
1
1
  module Telegraph
2
2
  module Parser
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3".freeze
4
4
  end
5
5
  end
@@ -3,6 +3,7 @@ require "telegraph/parser/errors"
3
3
  require "telegraph/parser/fetcher"
4
4
  require "telegraph/parser/parser"
5
5
  require "telegraph/parser/article"
6
+ require "telegraph/parser/formats"
6
7
 
7
8
  module Telegraph
8
9
  module Parser
@@ -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.2
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-12 00:00:00.000000000 Z
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