deba 0.2.0 → 0.3.0

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: 5a5d114eb0f4daf810581ebc534d9bcc6bac75b7
4
- data.tar.gz: 1ccd7b26a3db08811b6eabbe07c9fd1c7afc2e6b
3
+ metadata.gz: 4bb2408108f8d55f9615dfe7076804f0514a31ad
4
+ data.tar.gz: 300e03f63676c61472dfca464fc578c4e192655f
5
5
  SHA512:
6
- metadata.gz: 6e38ece0ad8a5c9394275921f1badc268ac6fa9b2cbf915a5fdb9faff576ad01edc7b3c2d260d9b17174917ab3e163d80de67c81682abeb6b7ecd917d4c36c19
7
- data.tar.gz: a5a6050046ab1635715f7d8c1f5b60289138b3031ecee9bdfd6ff636e893e8417c05127e1f9c53782bc8cfbeb938433c5258c79dc5f42a0a931f60ce7c972ed7
6
+ metadata.gz: 6e83bfef880ff0cd253681079351f311025ea8af5c9f94ce183fa7449a250c0b15efc515391a75167beb84d52d5bb6b16f182ad0bf2e9cbe919c9222906066c0
7
+ data.tar.gz: 68b754c99c9697dcd68d745c40cfb34156d093f26557cde21e17ef4fd82214def9bff7241a5ae80f6cfaf0bb6a6bb33beb576b965138182570d6cc1e434de518
data/deba.gemspec CHANGED
@@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.13"
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_dependency "nokogiri"
26
+ spec.add_dependency "nokogiri", "~> 1.7"
27
27
  end
@@ -0,0 +1,15 @@
1
+ class Deba::Document
2
+ attr_reader :blocks
3
+
4
+ def initialize
5
+ @blocks = []
6
+ end
7
+
8
+ def <<(block)
9
+ @blocks << block
10
+ end
11
+
12
+ def to_s
13
+ @blocks.map { |block| block.to_s }.join.strip
14
+ end
15
+ end
@@ -5,18 +5,18 @@ class Deba::Extractor
5
5
 
6
6
  attr_reader :blocks
7
7
 
8
- def initialize(doc)
9
- @doc = doc
8
+ def initialize(node)
9
+ @node = node
10
10
  end
11
11
 
12
12
  def extract
13
- @blocks = []
14
13
  @just_appended_br = false
15
- @text_run = Deba::TextRunner.new(self)
14
+ @document = Deba::Document.new
15
+ @text_run = Deba::TextRunner.new(@document)
16
16
 
17
- process(@doc.root)
17
+ process(@node)
18
18
 
19
- @blocks.map { |block| block.to_s }.join
19
+ @document
20
20
  end
21
21
 
22
22
  def process(node)
@@ -1,6 +1,6 @@
1
1
  class Deba::TextRunner
2
- def initialize(extractor)
3
- @extractor = extractor
2
+ def initialize(document)
3
+ @document = document
4
4
 
5
5
  start
6
6
  end
@@ -9,22 +9,22 @@ class Deba::TextRunner
9
9
  @segments << segment
10
10
  end
11
11
 
12
- def break(block_type = Deba::Paragraph, param = nil)
12
+ def break(*args)
13
13
  finish
14
- start(block_type, param)
14
+ start(*args)
15
15
  end
16
16
 
17
17
  def finish
18
18
  return unless present?
19
19
 
20
- block = @param.nil? ? @block_type.new(@segments) : @block_type.new(@segments, @param)
21
- @extractor.blocks << block
20
+ @args.unshift(@segments)
21
+ @document << @block_type.new(*@args)
22
22
  end
23
23
 
24
- def start(block_type = Deba::Paragraph, param = nil)
24
+ def start(*args)
25
25
  @segments = []
26
- @block_type = block_type
27
- @param = param
26
+ @block_type = args.shift
27
+ @args = args
28
28
  end
29
29
 
30
30
  def present?
data/lib/deba.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  require "nokogiri"
2
2
 
3
3
  module Deba
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
6
6
 
7
7
  require "deba/utils"
8
8
  require "deba/stringifier"
9
+ require "deba/document"
9
10
  require "deba/break"
10
11
  require "deba/heading"
11
12
  require "deba/paragraph"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brenton "B-Train" Fletcher
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: nokogiri
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '1.7'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '1.7'
55
55
  description: Deba takes a HTML document or fragment and extracts the text content
56
56
  into a plaintext format that is a strict subset of markdown.
57
57
  email:
@@ -70,6 +70,7 @@ files:
70
70
  - deba.gemspec
71
71
  - lib/deba.rb
72
72
  - lib/deba/break.rb
73
+ - lib/deba/document.rb
73
74
  - lib/deba/extractor.rb
74
75
  - lib/deba/heading.rb
75
76
  - lib/deba/paragraph.rb