class DiaryConsoleView
A console view class for the Learning Diary
Public Class Methods
new(diary = nil)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 6 def initialize(diary = nil) return if diary.nil? @diary = diary @paragraphs = diary.paragraphs @credits = diary.standard_credits @credits_total = diary.standard_credits_total @impact = diary.impact_credits @impact_total = diary.impact_credits_total @total = diary.credits_total end
Public Instance Methods
output(diary = nil)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 17 def output(diary = nil) initialize(diary) output_str end
Private Instance Methods
add_impact_statement(e)
click to toggle source
@param [Array] e element - statement array from impact_statement(paragraph)
in
the form [has_info?(Boolean), text(String)]
# File lib/docfolio/views/diary_console_view.rb, line 125 def add_impact_statement(e) if e[0] == false impact_err(e[1]) else "\n\n#{e[1]}\n\n" end end
content(tag) { |p| ... }
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 67 def content(tag) arr = [] @paragraphs.each do |p| if block_given? # yields the whole paragraph for further processing arr = yield p if p.tag?(tag) else # strip tag texts to an array of one text element per tag text = p.send(tag).strip arr << text unless text == '' end end arr end
credit_amount(amount)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 231 def credit_amount(amount) str = "#{amount}".rjust(4) str << " mins\n" end
credit_line(p)
click to toggle source
@[param] p paragraph
# File lib/docfolio/views/diary_console_view.rb, line 140 def credit_line(p) st = p.start_time fin = p.end_time amount = ((fin - st) / 60).to_i cr = "Impact Credit Claimed: #{amount} mins" cr += ' based on an original period of study and reflection from' cr + " #{print_date_and_time(st)} to #{end_time(st, fin)}\n" end
credit_period(prev_credit, credit, i)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 225 def credit_period(prev_credit, credit, i) str = start_time(credit[0], prev_credit[0], i).rjust(16) str << ' - ' str << end_time(credit[0], credit[1]).ljust(16) end
credits_breakdown(credits_array)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 80 def credits_breakdown(credits_array) return '' if credits_array.empty? str = '' credit_count = credits_array.count - 1 0.upto(credit_count) do |i| prev_credit, credit = elements(credits_array, i) str << take_credit(prev_credit, credit, i) end str + sub_total_line end
credits_str(str = '')
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 53 def credits_str(str = '') str += section_str('CREDITS BREAKDOWN', credits_breakdown(@credits)) str += mins2hour(@credits_total) + "\n" unless @credits_total == 0 str += section_str('IMPACT BREAKDOWN', credits_breakdown(@impact)) str += mins2hour(@impact_total) + "\n" unless @impact_total == 0 str += section_str('TOTAL CREDITS CLAIMED', credits_total(@total)) str end
credits_total(total)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 62 def credits_total(total) return '' if total == 0 total_line + mins2hour(total) end
elements(a, i)
click to toggle source
@return [Array] The previous and current elements in the array
# File lib/docfolio/views/diary_console_view.rb, line 193 def elements(a, i) i > 0 ? [a[i - 1], a[i]] : [[], a[i]] end
end_time(st, fin)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 221 def end_time(st, fin) on_same_day?(st, fin) ? print_just_time(fin) : print_time_and_date(fin) end
impact()
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 99 def impact arr = [] old_cr = [] date = '' content(:I) { |p| old_cr = credit_line(p); break } statement_a = [] content(:I) do |p| date = strftime(p.start_time, '%e-%b-%y').underline sta = impact_statement(p) cr = credit_line(p) if cr != old_cr # group claims of the same time/credit arr << statement_line(date, statement_a, old_cr) statement_a = [] statement_a << add_impact_statement(sta) old_cr = cr next end statement_a << add_impact_statement(sta) end line = statement_line(date, statement_a, old_cr) arr << line unless line.nil? arr end
impact_err(sta)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 157 def impact_err(sta) ret = "#{sta}" + " Warning - this impact statement does"\ " not pertain to any learning points or reflection.".colorize(:red) "\n\n#{ret}\n\n" end
impact_statement(paragraph)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 149 def impact_statement(paragraph) arr = [] ref = rm_colour(reflections(paragraph).join(' ')) paragraph.each { |tag| arr << tag[1] if tag[0] == :I } sta = arr.join(' ') ref == '' ? [false, sta] : [true, "#{ref}\n\n#{sta}"] end
learning_str(str = '')
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 44 def learning_str(str = '') str += section_str('LEARNING POINTS', content(:LP), true) str += section_str('REFLECTION', reflection, true) str += section_str('IMPACT', impact) str += section_str('FURTHER STUDY', content(:DEN), true) str += section_str('OTHER NOTES', content(:NOTE)) str end
on_same_day?(time1, time2)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 187 def on_same_day?(time1, time2) one_day = 60 * 60 * 24 (time1.to_i / one_day).to_i == (time2.to_i / one_day).to_i end
output_str()
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 24 def output_str str = '' sig_event = @diary.significant_event? str += "SIGNIFICANT EVENT\n\n" if sig_event str += section_str('TITLE', content(:TITLE)) str += section_str('DATE OF EVENT', content(:SEA)) str += section_str('WHO WAS INVOLVED', content(:INVOLVED)) str += section_str('INTRODUCTION', content(:INTRO)) str += section_str('WHAT HAPPENED?', content(:WHAT)) str += section_str('WHY DID IT HAPPEN?', content(:WHY)) str += section_str('HOW DID YOU AND THE OTHERS INVOLVED FEEL?', content(:FEELINGS)) str += section_str('WHAT WENT WELL?', content(:WELL)) str += section_str('WHAT COULD HAVE BEEN DONE DIFFERENTLY?', content(:DIFFERENT)) str += section_str('WHAT NEEDS TO CHANGE?', content(:CHANGE)) str += section_str('WHAT HAS CHANGED?', content(:CHANGED)) str += learning_str str += credits_str str.gsub(/ \n/, "\n") end
print_date_and_time(t)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 205 def print_date_and_time(t) strftime(t, '%e-%b-%y %H:%M') end
print_just_time(t)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 201 def print_just_time(t) strftime(t, '%H:%M') end
print_time_and_date(t)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 209 def print_time_and_date(t) strftime(t, '%H:%M (%-e-%b)') end
reflection()
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 91 def reflection arr = [] content(:R) do |p| arr += reflections(p) end arr end
reflections(paragraph)
click to toggle source
@param [Array] paragraph A paragraph containing one or more reflections.
The paragraph is an array of tags of the form [tag symbol, string]
@return an array of reflections The reflection text is returned with preceeding learning points formatted
in a different style. A learning point is attached to the reflection if it preceeds the reflection, is in the same paragraph and there are no other intervening reflections in the same paragraph i.e. Within the same paragraph, a reflection will take the preceeding LPs and then leave subsequent LPs which will be picked up by a subsequent reflection if there is one. Such successive reflections, within the same paragraph, can be placed in order and in context when reported.
# File lib/docfolio/views/diary_console_view.rb, line 174 def reflections(paragraph) arr = [] lp = '' paragraph.each do |tag| if tag[0] == :R arr << (lp + tag[1].colorize(:green)) lp = '' end lp += (tag[1] + ' ').colorize(:light_black) if tag[0] == :LP end arr end
start_time(cr, prev_cr, i)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 213 def start_time(cr, prev_cr, i) if i == 0 # first line always has the full date and time print_date_and_time(cr) else on_same_day?(cr, prev_cr) ? print_just_time(cr) : print_date_and_time(cr) end end
statement_line(date, statement_a, old_cr)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 133 def statement_line(date, statement_a, old_cr) return if statement_a.empty? statement = statement_a.join "\n#{date}#{statement}#{old_cr}".gsub(/\n\n\n\n/, "\n\n") end
strftime(t, format)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 197 def strftime(t, format) t.strftime(format) end
take_credit(prev_credit, credit, i)
click to toggle source
# File lib/docfolio/views/diary_console_view.rb, line 236 def take_credit(prev_credit, credit, i) str = credit_period(prev_credit, credit, i) str << credit_amount(credit[2]) end