Class: GroffParser::Engine
- Inherits:
-
Object
- Object
- GroffParser::Engine
- Defined in:
- lib/groff_parser/engine.rb
Overview
A handy class who offers some methods to handle multiple documents at the same time
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#apply_to(*args) {|parse(args.join(" "))| ... } ⇒ Object
Executes a passed block, giving a GroffParser::Document as argument.
-
#apply_to_all(zipped = nil) ⇒ nil
Executes a passed block over all the documents in the current directory, giving a GroffParser::Document as argument for each block execution.
-
#initialize(path) ⇒ GroffParser::Engine
constructor
Stores a path, this one can be a path to a directory or to an specific file, use the proper class methods is up to you.
-
#parse(document_path, zipped = nil) ⇒ GroffParser::Document
Parse a document located on a given path, if the document is contained inside of the ‘@path` variable you can pass only the document name otherwise it searchs for path provided as a full path.
-
#parse_all(zipped = nil) ⇒ Array<GroffParser::Document>
Parse all documents in a given directory, with a given format.
Constructor Details
#initialize(path) ⇒ GroffParser::Engine
Stores a path, this one can be a path to a directory or to an specific file, use the proper class methods is up to you
26 27 28 |
# File 'lib/groff_parser/engine.rb', line 26 def initialize(path) @path = path || Dir.pwd end |
Instance Attribute Details
#path ⇒ Object
11 12 13 |
# File 'lib/groff_parser/engine.rb', line 11 def path @path end |
Instance Method Details
#apply_to(*args) {|parse(args.join(" "))| ... } ⇒ Object
Executes a passed block, giving a GroffParser::Document as argument
86 87 88 |
# File 'lib/groff_parser/engine.rb', line 86 def apply_to(*args) yield parse(args.join(" ")) end |
#apply_to_all(zipped = nil) ⇒ nil
Executes a passed block over all the documents in the current directory, giving a GroffParser::Document as argument for each block execution
103 104 105 106 107 108 109 |
# File 'lib/groff_parser/engine.rb', line 103 def apply_to_all(zipped = nil) search_path = zipped ? "#{path}/*.gz" : "#{path}/*" Dir.glob(search_path) do |document| yield parse(document, zipped) end end |
#parse(document_path, zipped = nil) ⇒ GroffParser::Document
Parse a document located on a given path, if the document is contained inside of the ‘@path` variable you can pass only the document name otherwise it searchs for path provided as a full path
49 50 51 52 53 |
# File 'lib/groff_parser/engine.rb', line 49 def parse(document_path, zipped = nil) dpath = document_path.include?(path) ? document_path : "#{path}/#{document_path}" Document.new(dpath, zipped) end |
#parse_all(zipped = nil) ⇒ Array<GroffParser::Document>
Parse all documents in a given directory, with a given format
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/groff_parser/engine.rb', line 67 def parse_all(zipped = nil) documents = [] search_path = zipped ? "#{path}/*.gz" : "#{path}/*[0-9]" Dir.glob(search_path) do |document| documents << parse(document, zipped) end documents end |