Class: Remind::Session
- Inherits:
-
Object
- Object
- Remind::Session
- Defined in:
- lib/remind/session.rb
Overview
A live Remind interpreter.
Remind is a program, not a library, and it shows in the shape of the C: today's date is a global, the current time is a global, and everything is computed against whatever those say. That has two consequences.
The first is a gift: "now" is settable, so a calculation against a fixed
date is reproducible rather than a reading off the clock. Converting a
reminder file to a calendar depends on it -- REM Mon means a different
first date tomorrow than it does today.
The second is that the state is per-process, not per-object. Two Sessions are two views of the same globals, so the lock is on the class and calls into the library are serialised whether they came from one Session or several.
Constant Summary collapse
- LOCK =
Mutex.new
- NO_TIME =
-1
- SECONDS_PER_MINUTE =
60
Instance Attribute Summary collapse
-
#native ⇒ Object
readonly
Returns the value of attribute native.
Instance Method Summary collapse
- #date(dse) ⇒ Object
-
#diagnostics=(wanted) ⇒ Object
Whether Remind prints its own diagnostics -- the offending line with a caret under it -- as well as this raising.
-
#dse(date) ⇒ Object
Remind's day count for a date, and back again.
- #error_message(code) ⇒ Object
-
#evaluate(expression) ⇒ Object
Evaluates a Remind expression: an Integer for a number, a String for a string, a Date for a date, a Time for a datetime, minutes since midnight for a time.
-
#initialize(native: Native.new, diagnostics: false) ⇒ Session
constructor
A new instance of Session.
-
#now=(time) ⇒ Object
Pins the date and the time of day together, for reminders that depend on the clock as well as the calendar.
-
#today ⇒ Object
The date every relative calculation is relative to.
-
#today=(date) ⇒ Object
Pins it, the way
remind --date=does. - #unpin_time ⇒ Object
-
#version ⇒ Object
The Remind release the library was built from, out of the library's own
version()rather than out of this gem's idea of it.
Constructor Details
Instance Attribute Details
#native ⇒ Object (readonly)
Returns the value of attribute native.
47 48 49 |
# File 'lib/remind/session.rb', line 47 def native @native end |
Instance Method Details
#date(dse) ⇒ Object
99 100 101 |
# File 'lib/remind/session.rb', line 99 def date(dse) Value.to_date(dse, native) end |
#diagnostics=(wanted) ⇒ Object
Whether Remind prints its own diagnostics -- the offending line with a caret under it -- as well as this raising.
105 106 107 108 109 |
# File 'lib/remind/session.rb', line 105 def diagnostics=(wanted) LOCK.synchronize do Runtime.point_errors(native, wanted) end end |
#dse(date) ⇒ Object
Remind's day count for a date, and back again.
95 96 97 |
# File 'lib/remind/session.rb', line 95 def dse(date) native.dse(date.year, date.month - 1, date.day) end |
#error_message(code) ⇒ Object
117 118 119 |
# File 'lib/remind/session.rb', line 117 def (code) native.(code).to_s end |
#evaluate(expression) ⇒ Object
Evaluates a Remind expression: an Integer for a number, a String for a string, a Date for a date, a Time for a datetime, minutes since midnight for a time.
session.evaluate("moonphase(today())") # => 46
session.evaluate("version()") # => "06.02.10"
61 62 63 64 65 |
# File 'lib/remind/session.rb', line 61 def evaluate(expression) LOCK.synchronize do evaluate_unlocked(expression) end end |
#now=(time) ⇒ Object
Pins the date and the time of day together, for reminders that depend on the clock as well as the calendar.
81 82 83 84 85 86 |
# File 'lib/remind/session.rb', line 81 def now=(time) LOCK.synchronize do pin_date(time.to_date) pin_time((time.hour * 60) + time.min) end end |
#today ⇒ Object
The date every relative calculation is relative to.
68 69 70 |
# File 'lib/remind/session.rb', line 68 def today date(native.read_global("DSEToday")) end |
#today=(date) ⇒ Object
Pins it, the way remind --date= does.
73 74 75 76 77 |
# File 'lib/remind/session.rb', line 73 def today=(date) LOCK.synchronize do pin_date(date) end end |
#unpin_time ⇒ Object
88 89 90 91 92 |
# File 'lib/remind/session.rb', line 88 def unpin_time LOCK.synchronize do pin_time(nil) end end |
#version ⇒ Object
The Remind release the library was built from, out of the library's own
version() rather than out of this gem's idea of it.
113 114 115 |
# File 'lib/remind/session.rb', line 113 def version evaluate("version()") end |