Class: MorningPagesJournal::CLI
- Inherits:
-
Object
- Object
- MorningPagesJournal::CLI
- Defined in:
- lib/morning-pages-journal/journal.rb
Instance Method Summary collapse
- #config ⇒ Object
- #config_words ⇒ Object
-
#initialize(command_line_arguments) ⇒ CLI
constructor
A new instance of CLI.
- #list(options) ⇒ Object
- #open ⇒ Object
- #opts ⇒ Object
- #stat(options) ⇒ Object
- #stats_words ⇒ Object
- #update_config(key, value) ⇒ Object
- #words(options) ⇒ Object
Constructor Details
#initialize(command_line_arguments) ⇒ CLI
Returns a new instance of CLI.
120 121 122 123 |
# File 'lib/morning-pages-journal/journal.rb', line 120 def initialize(command_line_arguments) @opts = command_line_arguments @opts[:config] = File.(@opts[:config]) end |
Instance Method Details
#config ⇒ Object
129 130 131 132 133 |
# File 'lib/morning-pages-journal/journal.rb', line 129 def config create_config_if_not_exists! @config ||= YAML::load(File.open(opts[:config])) end |
#config_words ⇒ Object
136 137 138 |
# File 'lib/morning-pages-journal/journal.rb', line 136 def config_words config["words"] || 750 end |
#list(options) ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/morning-pages-journal/journal.rb', line 151 def list() journal = MorningPagesJournal::Journal.new(:base_folder => config["folder"]) month_name = "" total_words = 0 journal.each_day([:range]) do |date| if month_name != date.strftime("%B") month_name = date.strftime("%B") puts month_name puts "-" * 100 end page = journal.get_page(date) words,color = if page if page.words.to_i < config_words [page.words.to_i, :red] else [page.words.to_i, :green] end else [0,:yellow] end total_words += words puts "#{date.strftime('%a, %d')}\t#{words.to_s.color(color)}\t" + ("="* (words/10).to_i).color(color) if date.strftime('%a') == "Sat" puts "" end end end |
#open ⇒ Object
144 145 146 147 148 149 |
# File 'lib/morning-pages-journal/journal.rb', line 144 def open journal = MorningPagesJournal::Journal.new(:base_folder => config["folder"]) editor = config["editor"] system "mkdir -p #{journal.today_folder} ; #{editor} #{journal.today_file}" end |
#opts ⇒ Object
125 126 127 |
# File 'lib/morning-pages-journal/journal.rb', line 125 def opts @opts end |
#stat(options) ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/morning-pages-journal/journal.rb', line 184 def stat() journal = MorningPagesJournal::Journal.new(:base_folder => config["folder"]) min_date = journal.min_date([:range]) days = ((journal.max_date+1) - min_date).to_i morning_pages = journal.pages_from(min_date,journal.max_date).size missed = days - morning_pages puts "Average Words:\t#{journal.average_words.to_i}\n" puts "From:\t#{min_date}" puts "To:\t#{journal.max_date}" puts "Total days:\t#{days}" puts "Morning pages:\t#{morning_pages}" puts "Missed:\t#{missed}" puts "\n" end |
#stats_words ⇒ Object
140 141 142 |
# File 'lib/morning-pages-journal/journal.rb', line 140 def stats_words (config["stats"] || 50).to_i end |
#update_config(key, value) ⇒ Object
208 209 210 211 212 213 214 215 |
# File 'lib/morning-pages-journal/journal.rb', line 208 def update_config(key,value) c = config c[key] = value File.open(opts[:config],"w+") do |f| f.write YAML::dump(c) end end |
#words(options) ⇒ Object
201 202 203 204 205 206 |
# File 'lib/morning-pages-journal/journal.rb', line 201 def words() journal = MorningPagesJournal::Journal.new(:base_folder => config["folder"]) journal.word_count([:range]).sort_by {|k,v| v}.reverse.take(stats_words).each do |e| puts "#{e[0]}\t#{e[1]}" end end |