Skip to content

Commit a284f03

Browse files
authored
Merge pull request #340 from Kobzol/rating-scale
Add support for rating scale question
2 parents 22eb576 + 53b5641 commit a284f03

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

verifier/src/api.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ pub enum Question {
145145
question_text: String,
146146
choice_table: ChoiceTable,
147147
},
148+
#[serde(rename = "rating_scale")]
149+
RatingScale { question_text: String },
148150
}
149151

150152
impl Question {
@@ -153,6 +155,7 @@ impl Question {
153155
Self::ChoiceList { question_text, .. } => question_text,
154156
Self::Input { question_text, .. } => question_text,
155157
Self::ChoiceTable { question_text, .. } => question_text,
158+
Self::RatingScale { question_text } => question_text,
156159
})
157160
}
158161

verifier/src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ impl markdown::Question<'_> {
185185
);
186186
}
187187
}
188+
(markdown::Answers::RatingScale, Question::RatingScale { .. }) => {}
188189
_ => {
189190
return Comparison::QuestionTypesDiffer {
190191
question: self.text.to_owned(),
@@ -228,6 +229,7 @@ enum QuestionType {
228229
SelectOne,
229230
SelectMany,
230231
Matrix,
232+
RatingScale,
231233
}
232234

233235
impl<'a> From<&'a Question> for QuestionType {
@@ -253,6 +255,7 @@ impl From<&markdown::Question<'_>> for QuestionType {
253255
markdown::Answers::SelectOne(_) => Self::SelectOne,
254256
markdown::Answers::SelectMany(_) => Self::SelectMany,
255257
markdown::Answers::Matrix { .. } => Self::Matrix,
258+
markdown::Answers::RatingScale => Self::RatingScale,
256259
}
257260
}
258261
}

verifier/src/markdown.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ pub fn parse(markdown: &str) -> anyhow::Result<Vec<Question>> {
4949
})
5050
} else if typ.starts_with("matrix") {
5151
ParserState::HalfMatrixText(text)
52+
} else if typ.starts_with("rating scale") {
53+
ParserState::Question(Question {
54+
text,
55+
answers: Answers::RatingScale,
56+
})
5257
} else {
5358
bail!("illegal question type: type='{}' question='{}'", typ, text);
5459
}
@@ -182,6 +187,7 @@ impl<'a> Question<'a> {
182187
#[derive(Debug, Clone)]
183188
pub enum Answers<'a> {
184189
FreeForm,
190+
RatingScale,
185191
SelectOne(Vec<&'a str>),
186192
SelectMany(Vec<&'a str>),
187193
Matrix {
@@ -200,6 +206,7 @@ impl Answers<'_> {
200206
answers1, answers2, ..
201207
} => answers1.is_empty() || answers2.is_empty(),
202208
Self::FreeForm => false,
209+
Self::RatingScale => false,
203210
}
204211
}
205212
}

verifier/src/render.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ pub fn render_questions(questions: &[Question], file: &Path) -> io::Result<()> {
3939
writeln!(file, "- {col}")?;
4040
}
4141
}
42+
Question::RatingScale { .. } => {
43+
writeln!(file, "Type: rating scale\n")?;
44+
}
4245
}
4346
writeln!(file)?;
4447
}

0 commit comments

Comments
 (0)