class DailyLog::LatestDate
Finds the latest past Date that we have an Entry
for in the local filesystem
Constants
- DATE_PATH_MATCHER
Match a file path to extract a date component
Public Instance Methods
find()
click to toggle source
The latest entry in the local file system
Returns Date Returns nil
# File lib/daily_log/latest_date.rb, line 14 def find return nil unless entry_paths.any? past_entries = entry_paths.map do |path| match = path.match(DATE_PATH_MATCHER) Date.parse(match.to_s) end.select { |date| date < today } past_entries.last end
to_date()
click to toggle source
Return the Date as a Date object
# File lib/daily_log/latest_date.rb, line 31 def to_date find end
to_s()
click to toggle source
Convert the Date to a String Returns String
# File lib/daily_log/latest_date.rb, line 26 def to_s find.to_s.strftime(Day::DATE_FORMAT) end
Private Instance Methods
entry_paths()
click to toggle source
# File lib/daily_log/latest_date.rb, line 41 def entry_paths Dir[File.join(Pathname.dirname, "**", "*.md")].sort end
today()
click to toggle source
# File lib/daily_log/latest_date.rb, line 37 def today @today = Date.today end