class Mumukit::Assistant::Narrator
A narrator can turn tips - generated by `Mumukit::Assistant` - into a humanized text with the same information but a bit more friendly. This text is called explanation.
The narrator uses some internationalized random phrases, and it does provide a seed as a construction argument to allow its testing.
Public Class Methods
new(seed)
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 8 def initialize(seed) @seed = seed end
random()
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 50 def self.random new seed(*5.times.map { random_index }) end
seed(r, i, o, m, e)
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 54 def self.seed(r, i, o, m, e) { retry: r, introduction: i, opening: o, middle: m, ending: e } end
Private Class Methods
random_index()
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 64 def self.random_index (0..2).to_a.sample end
Public Instance Methods
compose_explanation(tips)
click to toggle source
Generated a markdown explanation using the seeded phrases. Uses `I18n` to get the appropriate locale.
# File lib/mumukit/assistant/narrator.rb, line 14 def compose_explanation(tips) "#{explanation_introduction_phrase}\n\n#{explanation_paragraphs(tips).join("\n\n")}\n\n#{retry_phrase}\n" end
compose_explanation_html(tips)
click to toggle source
Generates an html explantion. See `compose_explanation`
# File lib/mumukit/assistant/narrator.rb, line 20 def compose_explanation_html(tips) Mumukit::ContentType::Markdown.to_html compose_explanation(tips) end
explanation_ending_paragraph(tip)
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 46 def explanation_ending_paragraph(tip) t :ending, tip: tip end
explanation_introduction_phrase()
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 28 def explanation_introduction_phrase t :introduction end
explanation_middle_paragraph(tip)
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 42 def explanation_middle_paragraph(tip) t :middle, tip: tip end
explanation_opening_paragraph(tip)
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 38 def explanation_opening_paragraph(tip) "#{tip.upcase_first}." end
explanation_paragraphs(tips)
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 32 def explanation_paragraphs(tips) tips.take(3).zip([:opening, :middle, :ending]).map do |tip, selector| send "explanation_#{selector}_paragraph", tip end end
retry_phrase()
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 24 def retry_phrase t :retry end
Private Instance Methods
t(key, args={})
click to toggle source
# File lib/mumukit/assistant/narrator.rb, line 60 def t(key, args={}) I18n.t "narrator.#{key}_#{@seed[key]}", args end