Class: FlycalCli::SlotFormatter
- Inherits:
-
Object
- Object
- FlycalCli::SlotFormatter
- Defined in:
- lib/flycal_cli/slot_formatter.rb
Class Method Summary collapse
- .format_header(from:, to:, duration:, calendars:, count:, template: nil) ⇒ Object
- .format_output(slots_by_day) ⇒ Object
- .strip_ansi(text) ⇒ Object
Class Method Details
.format_header(from:, to:, duration:, calendars:, count:, template: nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/flycal_cli/slot_formatter.rb', line 6 def format_header(from:, to:, duration:, calendars:, count:, template: nil) lines = [] lines << Locale.t( "slots.header", count: underline(count), from: underline(Locale.format_long_date(from)), to: underline(Locale.format_long_date(to)), duration: underline(duration), template: underline(template.to_s) ) calendars.each do |cal| lines << "- #{cal[:name]}" end lines << "link: #{google_calendar_day_url(from)}" lines.join("\n") end |
.format_output(slots_by_day) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/flycal_cli/slot_formatter.rb', line 23 def format_output(slots_by_day) lines = [] slots_by_day.sort_by(&:first).each do |date, slots| lines << "" unless lines.empty? lines << underline(day_header(date)) slots.each do |start_at, end_at| lines << slot_range(start_at, end_at) end end lines.join("\n") end |
.strip_ansi(text) ⇒ Object
37 38 39 |
# File 'lib/flycal_cli/slot_formatter.rb', line 37 def strip_ansi(text) text.to_s.gsub(/\e\[[0-9;]*m/, "") end |