Class: GroffParser::Document
- Inherits:
-
Object
- Object
- GroffParser::Document
- Defined in:
- lib/groff_parser/document.rb
Overview
A class representing a specific document to be parsed
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#formatted_content(format, flags = {}) ⇒ String
Content of the document in a especific format.
- #groff(flags = {}) ⇒ Object
-
#initialize(path, zipped = nil) ⇒ GroffParser::Document
constructor
Initializes the document class.
-
#raw_content(flags = {}) ⇒ String
Raw content of the document, without being parsed, in pure groff format.
-
#section(name) ⇒ String?
Currently in beta, given a section name it tries to search within the current document for a title passed as a parameter and return the contents within the title and the next one.
Constructor Details
#initialize(path, zipped = nil) ⇒ GroffParser::Document
Initializes the document class
23 24 25 26 |
# File 'lib/groff_parser/document.rb', line 23 def initialize(path, zipped = nil) @path = path @zipped = zipped end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/groff_parser/document.rb', line 7 def path @path end |
Instance Method Details
#formatted_content(format, flags = {}) ⇒ String
Content of the document in a especific format
100 101 102 |
# File 'lib/groff_parser/document.rb', line 100 def formatted_content(format, flags = {}) `#{get} #{@path} | groff -mandoc -T#{format} #{formatted_flags(flags)}` end |
#groff(flags = {}) ⇒ Object
66 67 68 |
# File 'lib/groff_parser/document.rb', line 66 def groff(flags = {}) `#{get} #{@path} | groff #{formatted_flags(flags)}` end |
#raw_content(flags = {}) ⇒ String
Raw content of the document, without being parsed, in pure groff format
82 83 84 |
# File 'lib/groff_parser/document.rb', line 82 def raw_content(flags = {}) @raw_content ||= `#{get} #{@path} #{formatted_flags(flags)}` end |
#section(name) ⇒ String?
Currently in beta, given a section name it tries to search within the current document for a title passed as a parameter and return the contents within the title and the next one
46 47 48 49 50 |
# File 'lib/groff_parser/document.rb', line 46 def section(name) raw_section = raw_content[/SH (?:\")?#{name}(?:\")?(.*?)SH/im] return raw_section.gsub("SH", "").gsub("#{name}", "") if raw_section end |