Class: CalendarAssistant::CLI::EventSetPresenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- CalendarAssistant::CLI::EventSetPresenter
- Defined in:
- lib/calendar_assistant/cli/event_set_presenter.rb
Direct Known Subclasses
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize(obj, config:, event_presenter_class: CLI::EventPresenter) ⇒ EventSetPresenter
constructor
A new instance of EventSetPresenter.
- #now!(event, printed_now, out:, presenter_class: CLI::EventPresenter) ⇒ Object
- #title ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(obj, config:, event_presenter_class: CLI::EventPresenter) ⇒ EventSetPresenter
Returns a new instance of EventSetPresenter.
4 5 6 7 8 |
# File 'lib/calendar_assistant/cli/event_set_presenter.rb', line 4 def initialize(obj, config:, event_presenter_class: CLI::EventPresenter) super(obj) @config = config @event_presenter_class = event_presenter_class end |
Instance Method Details
#description ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/calendar_assistant/cli/event_set_presenter.rb', line 21 def description out = StringIO.new if __getobj__.is_a?(EventSet::Hash) events.each do |key, value| out.puts rainbow.wrap(key.to_s.capitalize + ":").bold.italic out.puts self.class.new(__getobj__.new(value), config: @config, event_presenter_class: @event_presenter_class).description end return out.string end _events = Array(events) return "No events in this time range.\n" if _events.empty? display_events = _events.select do |event| !@config.setting(CalendarAssistant::Config::Keys::Options::COMMITMENTS) || event.commitment? end printed_now = false display_events.each_with_object([]) do |event, out| printed_now = now! event, printed_now, out: out, presenter_class: @event_presenter_class out << @event_presenter_class.new(event).description pp event if @config.debug? end.join("\n") end |
#now!(event, printed_now, out:, presenter_class: CLI::EventPresenter) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/calendar_assistant/cli/event_set_presenter.rb', line 49 def now!(event, printed_now, out:, presenter_class: CLI::EventPresenter) return true if printed_now return false if event.start_date != Date.today if event.start_time > Time.now out << presenter_class.new(CalendarAssistant::CLI::Helpers.now).description return true end false end |
#title ⇒ Object
17 18 19 |
# File 'lib/calendar_assistant/cli/event_set_presenter.rb', line 17 def title rainbow.wrap("#{event_repository.calendar.id} (all times in #{event_repository.calendar.time_zone})\n").italic end |
#to_s ⇒ Object
10 11 12 13 14 15 |
# File 'lib/calendar_assistant/cli/event_set_presenter.rb', line 10 def to_s [ title, description, ].join("\n") end |