Class: Search::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo_developer/app/services/search/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc_type, config, path) ⇒ Document

Returns a new instance of Document.



5
6
7
8
9
# File 'lib/nexmo_developer/app/services/search/document.rb', line 5

def initialize(doc_type, config, path)
  @doc_type = doc_type
  @config   = config
  @path     = Pathname.new(path)
end

Instance Attribute Details

#config ⇒ Object (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/nexmo_developer/app/services/search/document.rb', line 3

def config
  @config
end

#doc_type ⇒ Object (readonly)

Returns the value of attribute doc_type.



3
4
5
# File 'lib/nexmo_developer/app/services/search/document.rb', line 3

def doc_type
  @doc_type
end

#path ⇒ Object (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/nexmo_developer/app/services/search/document.rb', line 3

def path
  @path
end

Instance Method Details

#articles ⇒ Object



11
12
13
14
15
# File 'lib/nexmo_developer/app/services/search/document.rb', line 11

def articles
  @articles ||= Nokogiri::HTML(body).split_html.map do |section_html|
    Search::Article.new(self, section_html)
  end
end

#body ⇒ Object



33
34
35
# File 'lib/nexmo_developer/app/services/search/document.rb', line 33

def body
  @body ||= Nexmo::Markdown::Renderer.new.call(document)
end

#description ⇒ Object



29
30
31
# File 'lib/nexmo_developer/app/services/search/document.rb', line 29

def description
  @description ||= frontmatter['description']
end

#document ⇒ Object



17
18
19
# File 'lib/nexmo_developer/app/services/search/document.rb', line 17

def document
  @document ||= File.read(@path)
end

#frontmatter ⇒ Object



21
22
23
# File 'lib/nexmo_developer/app/services/search/document.rb', line 21

def frontmatter
  @frontmatter ||= YAML.safe_load(document)
end

#title ⇒ Object



25
26
27
# File 'lib/nexmo_developer/app/services/search/document.rb', line 25

def title
  @title ||= frontmatter['title']
end