Class: DmtdVbmappData::GuideChapter

Inherits:
Object
  • Object
show all
Defined in:
lib/dmtd_vbmapp_data/guide_chapter.rb

Overview

Provides for the retrieving of VB-MAPP Guide chapters from the VB-MAPP Data Server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ GuideChapter

Note:

This method does not block, simply creates an accessor and returns

Creates an accessor for the VB-MAPP Guide Chapter on the VB-MAPP Data Server

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :client (Client)

    A client instance

  • :chapter_num (Integer)

    The number (index 0..n) of the chapter in the Guide’s index array

  • :chapter_index_json (Hash)

    The guide index json for the chapter in the format described at 1/guide/index REST api - Chapter Fields



28
29
30
31
32
33
34
35
36
# File 'lib/dmtd_vbmapp_data/guide_chapter.rb', line 28

def initialize(opts)
  @client = opts.fetch(:client)
  @chapter_num = opts.fetch(:chapter_num).to_i

  index_json = opts.fetch(:chapter_index_json)
  @title = index_json[:title]

  @sections_index = index_json[:sections]
end

Instance Attribute Details

#chapter_numObject (readonly)

Returns the value of attribute chapter_num.



14
15
16
# File 'lib/dmtd_vbmapp_data/guide_chapter.rb', line 14

def chapter_num
  @chapter_num
end

#chapter_titleString (readonly)

Returns the title of the chapter.

Returns:

  • (String)

    the title of the chapter



18
# File 'lib/dmtd_vbmapp_data/guide_chapter.rb', line 18

attr_reader :title

#clientObject (readonly)

Returns the value of attribute client.



10
11
12
# File 'lib/dmtd_vbmapp_data/guide_chapter.rb', line 10

def client
  @client
end

#titleObject (readonly)

Returns the value of attribute title.



18
19
20
# File 'lib/dmtd_vbmapp_data/guide_chapter.rb', line 18

def title
  @title
end

Instance Method Details

#contentString

Note:

This method does block as the content is retrieved

Returns The preamble of the Guide’s chapter.

Returns:

  • (String)

    The preamble of the Guide’s chapter



41
42
43
44
45
# File 'lib/dmtd_vbmapp_data/guide_chapter.rb', line 41

def content
  @content = retrieve_guide_chapter[:content] if @content.nil?

  @content
end

#sectionsArray<GuideChapterSection>

Note:

This method does not block

Returns all of the the VB-MAPP Guide’s DmtdVbmappData::GuideChapterSection instances.

Returns:



50
51
52
53
54
55
56
# File 'lib/dmtd_vbmapp_data/guide_chapter.rb', line 50

def sections
  @sections = @sections_index.map.with_index do |section_index_json, section_num|
    GuideChapterSection.new(client: client, chapter_num: chapter_num, section_num: section_num, section_index_json: section_index_json)
  end if @sections.nil?

  @sections
end