Class: Devcenter::ArticleFile
- Inherits:
-
Object
- Object
- Devcenter::ArticleFile
- Defined in:
- lib/devcenter/article_file.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#parsing_error ⇒ Object
readonly
Returns the value of attribute parsing_error.
-
#toc ⇒ Object
readonly
Returns the value of attribute toc.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ ArticleFile
constructor
A new instance of ArticleFile.
Constructor Details
#initialize(opts = {}) ⇒ ArticleFile
Returns a new instance of ArticleFile.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/devcenter/article_file.rb', line 10 def initialize(opts = {}) @metadata = opts[:metadata] || OpenStruct.new @content = opts[:content] || '' begin @html = ::DevcenterParser.to_html(@content) rescue Exception => e @parsing_error = e.to_s @html = '' end @toc = Nokogiri::HTML(@html).search('h2') end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
8 9 10 |
# File 'lib/devcenter/article_file.rb', line 8 def content @content end |
#html ⇒ Object (readonly)
Returns the value of attribute html.
8 9 10 |
# File 'lib/devcenter/article_file.rb', line 8 def html @html end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/devcenter/article_file.rb', line 8 def @metadata end |
#parsing_error ⇒ Object (readonly)
Returns the value of attribute parsing_error.
8 9 10 |
# File 'lib/devcenter/article_file.rb', line 8 def parsing_error @parsing_error end |
#toc ⇒ Object (readonly)
Returns the value of attribute toc.
8 9 10 |
# File 'lib/devcenter/article_file.rb', line 8 def toc @toc end |
Class Method Details
.read(src_path) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/devcenter/article_file.rb', line 22 def self.read(src_path) src = IO.read(src_path) , content = src.split(/\r*\n\r*\n/, 2) = OpenStruct.new YAML.load() new(metadata: , content: content) end |