Class: DmtdVbmappData::ProtocolAreaGroup
- Inherits:
-
Object
- Object
- DmtdVbmappData::ProtocolAreaGroup
- 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
-
#area ⇒ Object
readonly
Returns the value of attribute area.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
Instance Method Summary collapse
-
#initialize(opts) ⇒ ProtocolAreaGroup
constructor
Creates an accessor for the VB-MAPP Area Group on the VB-MAPP Data Server.
-
#levels ⇒ Symbol
All of the area group’s levels.
-
#questions(opts = {}) ⇒ Array<ProtocolAreaQuestion>
All of the area group’s ProtocolAreaQuestion instances.
Constructor Details
#initialize(opts) ⇒ ProtocolAreaGroup
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.
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
#area ⇒ Object (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 |
#client ⇒ Object (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 |
#group ⇒ Object (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
#levels ⇒ Symbol
This method does not block
Returns 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>
This method does block as the content is retrieved
Returns all of the area group’s DmtdVbmappData::ProtocolAreaQuestion instances.
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 |