Class: Remind::Source
- Inherits:
-
Object
- Object
- Remind::Source
- Defined in:
- lib/remind/source.rb
Overview
A file of reminders, read by Remind.
Named Source rather than File because it lives inside Remind, where a
class called File would shadow the one in the standard library for every
other file in the gem.
A reminder file is not a list of lines. A backslash joins two of them into
one; INCLUDE splices another file into the middle; INCLUDEsys reaches
into the system directory for the holiday files that ship with Remind. Any
reader that treats the file as text gets all three wrong, so this one does
not read text: IncludeFile opens the file and ReadLine hands back one
logical line at a time, out of whichever file is currently on Remind's
stack, exactly as remind itself sees them.
What comes out is the lines Remind can turn into events. Everything else -- SET, IF, OMIT, comments, RUN reminders -- is skipped, because it is a command rather than an appointment.
Constant Summary collapse
- STDIN =
Remind reads standard input under this name, the same as the program.
"-"
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#initialize(path, session: Session.new) ⇒ Source
constructor
A new instance of Source.
-
#lines ⇒ Object
The logical lines, continuations joined and includes spliced.
-
#reminders ⇒ Object
Every reminder in the file, in the order the file gives them.
Constructor Details
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
31 32 33 |
# File 'lib/remind/source.rb', line 31 def path @path end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
31 32 33 |
# File 'lib/remind/source.rb', line 31 def session @session end |
Instance Method Details
#lines ⇒ Object
The logical lines, continuations joined and includes spliced.
54 55 56 57 58 59 60 61 62 |
# File 'lib/remind/source.rb', line 54 def lines Enumerator.new do |line| open while (text = read) line << text end end end |
#reminders ⇒ Object
Every reminder in the file, in the order the file gives them. Lazy: a file can INCLUDE another, and a caller that only wants the first few should not pay for the rest.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/remind/source.rb', line 41 def reminders Enumerator.new do |found| lines.each do |line| reminder = Reminder.parse(line, session: session) if reminder found << reminder end end end end |