Class: Devcenter::ArticleFile

Inherits:
Object
  • Object
show all
Defined in:
lib/devcenter/article_file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#contentObject (readonly)

Returns the value of attribute content.



8
9
10
# File 'lib/devcenter/article_file.rb', line 8

def content
  @content
end

#htmlObject (readonly)

Returns the value of attribute html.



8
9
10
# File 'lib/devcenter/article_file.rb', line 8

def html
  @html
end

#metadataObject (readonly)

Returns the value of attribute metadata.



8
9
10
# File 'lib/devcenter/article_file.rb', line 8

def 
  @metadata
end

#parsing_errorObject (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

#tocObject (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