groff_parser 0.1.0 → 0.2.0
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.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/lib/groff_parser/document.rb +5 -1
- data/lib/groff_parser/engine.rb +11 -13
- data/lib/groff_parser/version.rb +1 -1
- data/test/document_test.rb +7 -3
- data/test/engine_test.rb +30 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4fc1b9649bdc2dcc2974e4a63fbe14cc9b792d4
|
4
|
+
data.tar.gz: 9ab8d0c06bcfcc6ad0411dcd7a336c90106ed2bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 477c47e9a716095b00130ae0821b0811a066698c787173951cf3faf7c4d577de748e078fa959541ce1f5d77db4ca8ea376b5dbe6673c403b4f7b4025dcde7d5f
|
7
|
+
data.tar.gz: e444620aa38927793be68cac6b5f469a99af7f34a4814dacafe3cce20e78e6995086173be1668e1b64e7a0bb859c4faf19d8db2aba657e0800685c986b52dd23
|
data/README.md
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
### Status
|
4
4
|
[](http://badge.fury.io/rb/groff_parser)
|
5
5
|
[](https://codeclimate.com/github/roperzh/groff_parser)
|
6
|
-
[](https://gemnasium.com/roperzh/groff_parser)
|
7
6
|
|
8
7
|
Tiny library to parse groff files, with some handy metods to manage directories with a lot of files
|
9
8
|
|
@@ -23,7 +22,7 @@ Or install it yourself as:
|
|
23
22
|
|
24
23
|
## Basic Usage
|
25
24
|
|
26
|
-
Coming soon, in the meantime you can read the [`docs`](http://rubydoc.info/gems/)
|
25
|
+
Coming soon, in the meantime you can read the [`docs`](http://rubydoc.info/gems/groff_parser)
|
27
26
|
|
28
27
|
|
29
28
|
## Contributing
|
@@ -4,6 +4,8 @@ module GroffParser
|
|
4
4
|
|
5
5
|
class Document
|
6
6
|
|
7
|
+
attr_accessor :path
|
8
|
+
|
7
9
|
# Initializes the document class
|
8
10
|
#
|
9
11
|
# @since 0.1.0
|
@@ -42,7 +44,9 @@ module GroffParser
|
|
42
44
|
# doesn't exist yet
|
43
45
|
|
44
46
|
def section(name)
|
45
|
-
raw_content[/SH
|
47
|
+
raw_section = raw_content[/SH (?:\")?#{name}(?:\")?(.*?)SH/im]
|
48
|
+
|
49
|
+
return raw_section.gsub("SH", "").gsub("#{name}", "") if raw_section
|
46
50
|
end
|
47
51
|
|
48
52
|
# Raw content of the document, without being parsed, in pure
|
data/lib/groff_parser/engine.rb
CHANGED
@@ -44,15 +44,12 @@ module GroffParser
|
|
44
44
|
#
|
45
45
|
# @param zipped [Boolean] indicates if the file is zipped or not (gzip)
|
46
46
|
#
|
47
|
-
# @
|
48
|
-
# dvi, html, lbp, lj4, ps, ascii, cp1047, latin1, utf8, X75, X75, X100, X100
|
49
|
-
#
|
50
|
-
# @return [String] the content of the document, parsed in the proper format
|
47
|
+
# @return [GroffParser::Document] the document, parsed and ready to be manipulated
|
51
48
|
|
52
|
-
def parse(document_path, zipped
|
49
|
+
def parse(document_path, zipped: zipped)
|
53
50
|
dpath = document_path.include?(path) ? document_path : "#{path}/#{document_path}"
|
54
51
|
|
55
|
-
Document.new(dpath, zipped: zipped)
|
52
|
+
Document.new(dpath, zipped: zipped)
|
56
53
|
end
|
57
54
|
|
58
55
|
# Parse all documents in a given directory, with a given format
|
@@ -65,14 +62,14 @@ module GroffParser
|
|
65
62
|
#
|
66
63
|
# @param zipped [Boolean] indicates if the file is zipped or not (gzip)
|
67
64
|
#
|
68
|
-
# @return [Array] an array of all the parsed documents
|
65
|
+
# @return [Array<GroffParser::Document>] an array of all the parsed documents
|
69
66
|
|
70
67
|
def parse_all(format: :utf8, zipped: false)
|
71
68
|
documents = []
|
72
69
|
search_path = zipped ? "#{path}/*.gz" : "#{path}/*[0-9]"
|
73
70
|
|
74
71
|
Dir.glob(search_path) do |document|
|
75
|
-
documents << parse(document, zipped
|
72
|
+
documents << parse(document, zipped: zipped)
|
76
73
|
end
|
77
74
|
|
78
75
|
documents
|
@@ -85,9 +82,8 @@ module GroffParser
|
|
85
82
|
# @example
|
86
83
|
# parser = GroffParser::Engine.new("/path/to/file")
|
87
84
|
# parser.apply { |document| document.parse }
|
88
|
-
#
|
89
85
|
|
90
|
-
def
|
86
|
+
def apply_to(*args)
|
91
87
|
yield parse(args.join(" "))
|
92
88
|
end
|
93
89
|
|
@@ -100,13 +96,15 @@ module GroffParser
|
|
100
96
|
# parser = GroffParser::Engine.new("/folder/with/some/files")
|
101
97
|
# parser.apply_all { |document| document.parse }
|
102
98
|
#
|
99
|
+
# @param zipped [Boolean] indicates if the file is zipped or not (gzip)
|
100
|
+
#
|
103
101
|
# @return [nil]
|
104
102
|
|
105
|
-
def
|
106
|
-
search_path =
|
103
|
+
def apply_to_all(zipped: false)
|
104
|
+
search_path = zipped ? "#{path}/*.gz" : "#{path}/*"
|
107
105
|
|
108
106
|
Dir.glob(search_path) do |document|
|
109
|
-
yield parse(
|
107
|
+
yield parse(document, zipped)
|
110
108
|
end
|
111
109
|
end
|
112
110
|
end
|
data/lib/groff_parser/version.rb
CHANGED
data/test/document_test.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require "test_helper"
|
1
|
+
require File.expand_path(File.join("test/test_helper"))
|
2
2
|
|
3
3
|
describe GroffParser::Document do
|
4
4
|
|
@@ -13,11 +13,11 @@ describe GroffParser::Document do
|
|
13
13
|
describe "#section" do
|
14
14
|
it "returns the contents of a section delimited by a given title" do
|
15
15
|
zipped_document.section("NAME").must_equal(
|
16
|
-
" \"
|
16
|
+
" \"\"\ngit \\- the stupid content tracker\n."
|
17
17
|
)
|
18
18
|
|
19
19
|
unzipped_document.section("NAME").must_equal(
|
20
|
-
" \"
|
20
|
+
" \"\"\ngit \\- the stupid content tracker\n."
|
21
21
|
)
|
22
22
|
end
|
23
23
|
|
@@ -26,6 +26,10 @@ describe GroffParser::Document do
|
|
26
26
|
unzipped_document.section("NAME")
|
27
27
|
)
|
28
28
|
end
|
29
|
+
|
30
|
+
it "returns nil if the provided section does not exists" do
|
31
|
+
zipped_document.section("UNEXISTENT_SECTION").must_equal(nil)
|
32
|
+
end
|
29
33
|
end
|
30
34
|
|
31
35
|
describe "#raw_content" do
|
data/test/engine_test.rb
CHANGED
@@ -5,17 +5,42 @@ describe GroffParser::Engine do
|
|
5
5
|
let(:engine) { GroffParser::Engine.new(path: "test/fixtures") }
|
6
6
|
|
7
7
|
describe "#parse" do
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
context "given a zipped document" do
|
9
|
+
it "returns a new GroffParser::Document instance" do
|
10
|
+
engine.parse("git.1.gz", zipped: true).class.must_equal(
|
11
|
+
GroffParser::Document
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "allows to retrieve information of the parsed file" do
|
16
|
+
engine.parse("git.1.gz", zipped: true).raw_content.must_equal(
|
17
|
+
GroffParser::Document.new("test/fixtures/git.1.gz", zipped: true)
|
18
|
+
.raw_content
|
19
|
+
)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "given an unzipped document" do
|
24
|
+
it "returns a new GroffParser::Document instance" do
|
25
|
+
engine.parse("git.1").class.must_equal(
|
26
|
+
GroffParser::Document
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "allows to retrieve information of the parsed file" do
|
31
|
+
engine.parse("git.1").raw_content.must_equal(
|
32
|
+
GroffParser::Document.new("test/fixtures/git.1.gz", zipped: true)
|
33
|
+
.raw_content
|
34
|
+
)
|
35
|
+
end
|
12
36
|
end
|
37
|
+
|
13
38
|
end
|
14
39
|
|
15
40
|
describe "#parse_all" do
|
16
41
|
it "returns an array with all the documents contents present in the path" do
|
17
42
|
engine.parse_all.must_equal(
|
18
|
-
[
|
43
|
+
[GroffParser::Document.new("test/fixtures/git.1", zipped: false)]
|
19
44
|
)
|
20
45
|
end
|
21
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groff_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Dip
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|