Class: Quirk::App
- Inherits:
-
Object
- Object
- Quirk::App
- Defined in:
- lib/quirk.rb
Instance Method Summary collapse
- #calendar(habit_id) ⇒ Object
- #edit ⇒ Object
-
#initialize(quirkfile = QUIRKFILE) ⇒ App
constructor
A new instance of App.
- #mark(habit_id) ⇒ Object
- #streaks ⇒ Object
- #year=(year) ⇒ Object
Constructor Details
Instance Method Details
#calendar(habit_id) ⇒ Object
22 23 24 |
# File 'lib/quirk.rb', line 22 def calendar(habit_id) puts cal.output(habit_id) end |
#edit ⇒ Object
26 27 28 |
# File 'lib/quirk.rb', line 26 def edit `#{EDITOR} #{QUIRKFILE} < \`tty\` > \`tty\`` end |
#mark(habit_id) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/quirk.rb', line 30 def mark(habit_id) contents = File.read(@quirkfile) return if !cal.has_habit?(habit_id) date = Quirk.today.strftime('%Y/%m/%d') match = contents.match(/^(#{date} .*)$/) if match # already has date, add habit to line old_line = match.captures[0] ids = old_line.strip.split(/\s+/, 2)[1].split(',').map(&:strip) ids << habit_id ids = ids.sort.uniq new_line = "#{date} #{ids.join(', ')}" contents.sub!(old_line, new_line) File.open(@quirkfile, 'w') { |f| f.print(contents) } else File.open(@quirkfile, 'a') { |f| f.puts("#{date} #{habit_id}") } end end |
#streaks ⇒ Object
49 50 51 |
# File 'lib/quirk.rb', line 49 def streaks puts cal.streaks end |
#year=(year) ⇒ Object
53 54 55 56 |
# File 'lib/quirk.rb', line 53 def year=(year) raise "Invalid year: #{year}" if year !~ /\d\d\d\d/ cal.year = year.to_i end |