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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 406e4d48011a846f365a37621e4ba1d91a9e5e35
4
- data.tar.gz: 02d97ad12f839e36b35ff9d7c82197e935e218c8
3
+ metadata.gz: c4fc1b9649bdc2dcc2974e4a63fbe14cc9b792d4
4
+ data.tar.gz: 9ab8d0c06bcfcc6ad0411dcd7a336c90106ed2bd
5
5
  SHA512:
6
- metadata.gz: 464732dbc63162c610ce01ec69e533ecd48bd4ae59893d5f26f9b3b3b3e4f3dcaee209573e8ac5fbc5c4daff547dfbd2828e0454a80b1ef47ffe79db426c42fd
7
- data.tar.gz: c80a4373eceaf28529e77d99323dc4fe308bc65518a2d18eb5551fee48482aa8f37aab212166513d22812444b1548d2c185b1998492be081c3d31f2bfdbcb3e6
6
+ metadata.gz: 477c47e9a716095b00130ae0821b0811a066698c787173951cf3faf7c4d577de748e078fa959541ce1f5d77db4ca8ea376b5dbe6673c403b4f7b4025dcde7d5f
7
+ data.tar.gz: e444620aa38927793be68cac6b5f469a99af7f34a4814dacafe3cce20e78e6995086173be1668e1b64e7a0bb859c4faf19d8db2aba657e0800685c986b52dd23
data/README.md CHANGED
@@ -3,7 +3,6 @@
3
3
  ### Status
4
4
  [![Gem Version](https://badge.fury.io/rb/groff_parser.png)](http://badge.fury.io/rb/groff_parser)
5
5
  [![Code Climate](https://codeclimate.com/github/roperzh/groff_parser.png)](https://codeclimate.com/github/roperzh/groff_parser)
6
- [![Dependencies](https://gemnasium.com/roperzh/groff_parser.png)](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 \"#{name}\"(.*?)SH/im].gsub("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
@@ -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
- # @param format [Symbol, String] indicates the output format, could be:
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, format: :utf8)
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).formatted_content(format)
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, format: format)
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 apply(*args)
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 apply_all(*args)
106
- search_path = args[0][:zipped] ? "#{path}/*.gz" : "#{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(*args)
107
+ yield parse(document, zipped)
110
108
  end
111
109
  end
112
110
  end
@@ -1,3 +1,3 @@
1
1
  module GroffParser
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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
- " \"NAME\"\ngit \\- the stupid content tracker\n."
16
+ " \"\"\ngit \\- the stupid content tracker\n."
17
17
  )
18
18
 
19
19
  unzipped_document.section("NAME").must_equal(
20
- " \"NAME\"\ngit \\- the stupid content tracker\n."
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
- it "returns the contents of a document, formatted by the requested format" do
9
- engine.parse("git.1.gz", true, format: :utf8).must_equal(
10
- `cat test/fixtures/git.1 | groff -mandoc -Tutf8`
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
- [`cat test/fixtures/git.1 | groff -mandoc -Tutf8`]
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.1.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-07 00:00:00.000000000 Z
11
+ date: 2014-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler