Class: DmtdVbmappData::ProtocolAreaGroup

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

Overview

Provides for the retrieving of VB-MAPP Protocol Area Group information from the VB-MAPP Data Server.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ ProtocolAreaGroup

Note:

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

Creates an accessor for the VB-MAPP Area Group on the VB-MAPP Data Server.

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :client (Client)

    A client instance

  • :area (String | Symbol)

    The vbmapp area of the group (:milestones, :barriers, :transitions’, :eesa)

  • :group_index_json (Hash)

    The vbmapp index json for the group in the format described at /1/protocol/index - GET REST api - Group Fields



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

def initialize(opts)
  @client = opts.fetch(:client)
  @area = opts.fetch(:area).to_sym

  index_json = opts.fetch(:group_index_json)
  @group = index_json[:group].to_sym
  @question_count = index_json[:question_count]
  @levels = index_json[:levels]
end

Instance Attribute Details

#areaObject (readonly)

Returns the value of attribute area.



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

def area
  @area
end

#clientObject (readonly)

Returns the value of attribute client.



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

def client
  @client
end

#groupObject (readonly)

Returns the value of attribute group.



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

def group
  @group
end

Instance Method Details

#levelsSymbol

Note:

This method does not block

Returns all of the area group’s levels.

Returns:

  • (Symbol)

    all of the area group’s levels



67
68
69
# File 'lib/dmtd_vbmapp_data/protocol_area_group.rb', line 67

def levels
  @levels.map {|level_json| level_json[:level].to_sym }
end

#questions(opts = {}) ⇒ Array<ProtocolAreaQuestion>

Note:

This method does block as the content is retrieved

Returns all of the area group’s DmtdVbmappData::ProtocolAreaQuestion instances.

Parameters:

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :level (String | Symbol)

    Filters the questions to the given level (may be null)

Returns:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dmtd_vbmapp_data/protocol_area_group.rb', line 43

def questions(opts = {})
  level_name = opts.fetch(:level, nil)

  @questions = retrieve_questions_json.map do |question_json|
    ProtocolAreaQuestion.new(client: client, area: area, group: group, question_json: question_json)
  end if @questions.nil?

  if level_name.nil?
    result = @questions
  else
    level_str = level_name.to_s
    level_desc = @levels.select {|level| level[:level].to_s == level_str}[0]
    start_num = level_desc[:start_question_num] + 1 # question_number is 1-based
    end_num = start_num + level_desc[:question_count]

    result = @questions.select {|question| question.number >= start_num && question.number <= end_num}
  end

  result
end