Class: WorkMd::Parser::Engine
- Inherits:
-
Object
- Object
- WorkMd::Parser::Engine
- Defined in:
- lib/work_md/parser/engine.rb
Overview
rubocop:disable Metrics/ClassLength
Defined Under Namespace
Classes: ParsedFile
Constant Summary collapse
- IS_FROZEN_ERROR_MESSAGE =
'WorkMd::Parser::Engine is frozen'
- IS_NOT_FROZEN_ERROR_MESSAGE =
'WorkMd::Parser::Engine is not frozen'
Instance Method Summary collapse
- #add_file(file) ⇒ Object
- #average_pomodoros ⇒ Object
-
#days_bars ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity.
- #difficulties ⇒ Object
- #done_tasks ⇒ Object
-
#freeze ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity.
-
#initialize ⇒ Engine
constructor
A new instance of Engine.
- #interruptions ⇒ Object
- #meetings ⇒ Object
- #observations ⇒ Object
- #pomodoros_bars(_file = nil) ⇒ Object
- #pomodoros_sum ⇒ Object
- #tasks ⇒ Object
Constructor Details
#initialize ⇒ Engine
Returns a new instance of Engine.
20 21 22 23 24 |
# File 'lib/work_md/parser/engine.rb', line 20 def initialize @t = WorkMd::Config.translations @parsed_files = [] @frozen = false end |
Instance Method Details
#add_file(file) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/work_md/parser/engine.rb', line 26 def add_file(file) raise IS_FROZEN_ERROR_MESSAGE if @frozen begin file_content = ::File.read(file) rescue Errno::ENOENT return end return unless file_content.start_with?('# ') @parsed_files.push(parse_file_content(file_content)) end |
#average_pomodoros ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/work_md/parser/engine.rb', line 77 def average_pomodoros if @parsed_files.size.positive? && pomodoros_sum.positive? return (pomodoros_sum.to_f / @parsed_files.size).round(1) end 0 end |
#days_bars ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/work_md/parser/engine.rb', line 103 def raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen return @days_bars if @days_bars @days_bars ||= @parsed_files.map do |f| pom = (1..f.pomodoros).map { '⬛' }.join mee = f.meetings.map { '📅' }.join int = f.interruptions.map { '⚠️' }.join dif = f.difficulties.map { '😓' }.join obs = f.observations.map { '📝' }.join tas = f.tasks.map { '✔️' }.join "(#{f.date}) #{pom}#{mee}#{int}#{dif}#{obs}#{tas}" end end |
#difficulties ⇒ Object
65 66 67 68 69 |
# File 'lib/work_md/parser/engine.rb', line 65 def difficulties raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen @difficulties ||= @parsed_files.map(&:difficulties).flatten end |
#done_tasks ⇒ Object
40 41 42 43 44 45 |
# File 'lib/work_md/parser/engine.rb', line 40 def done_tasks raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen @done_tasks ||= tasks.select { |t| t.start_with?('x]') || t.start_with?('X]') } end |
#freeze ⇒ Object
rubocop:enable Metrics/CyclomaticComplexity rubocop:enable Metrics/PerceivedComplexity
123 124 125 |
# File 'lib/work_md/parser/engine.rb', line 123 def freeze @frozen = true end |
#interruptions ⇒ Object
59 60 61 62 63 |
# File 'lib/work_md/parser/engine.rb', line 59 def interruptions raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen @interruptions ||= @parsed_files.map(&:interruptions).flatten end |
#meetings ⇒ Object
53 54 55 56 57 |
# File 'lib/work_md/parser/engine.rb', line 53 def meetings raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen @meetings ||= @parsed_files.map(&:meetings).flatten end |
#observations ⇒ Object
71 72 73 74 75 |
# File 'lib/work_md/parser/engine.rb', line 71 def observations raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen @observations ||= @parsed_files.map(&:observations).flatten end |
#pomodoros_bars(_file = nil) ⇒ Object
92 93 94 95 96 97 98 99 |
# File 'lib/work_md/parser/engine.rb', line 92 def (_file = nil) raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen @pomodoros_bars ||= @parsed_files.map do |f| "(#{f.date}) #{(1..f.pomodoros).map { '⬛' }.join}" end end |
#pomodoros_sum ⇒ Object
85 86 87 88 89 90 |
# File 'lib/work_md/parser/engine.rb', line 85 def pomodoros_sum raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen @pomodoros_sum ||= @parsed_files.reduce(0) { |sum, f| sum + f.pomodoros || 0 } end |
#tasks ⇒ Object
47 48 49 50 51 |
# File 'lib/work_md/parser/engine.rb', line 47 def tasks raise IS_NOT_FROZEN_ERROR_MESSAGE unless @frozen @tasks ||= @parsed_files.map(&:tasks).flatten end |