module ClockCondense
ClockCondense — trim clock tick body lines for single-line IRC replies. Public: condense_line, tick_body_lines, tick_led_body_lines, bare_tick? Depends: TextUtil Tests: test/lib/clock_condense_test.rb
Constants
- MAX_ASSOCIATION_LINES
- MAX_BODY_LINE
Public Instance Methods
Source
# File lib/clock/condense.rb, line 45 def bare_tick?(led_lines:, association_lines:, time_label: nil) assoc = Array(association_lines) .first(MAX_ASSOCIATION_LINES) .map { |line| full_line(line) } .reject(&:empty?) assoc.empty? && redundant_led?(Array(led_lines).map(&:to_s).reject(&:empty?), time_label) end
Source
# File lib/clock/condense.rb, line 16 def condense_line(text, max: MAX_BODY_LINE) TextUtil.truncate(TextUtil.squish(text), max) end
Source
# File lib/clock/condense.rb, line 20 def full_line(text) TextUtil.squish(text).sub(/\A\d+\.\s+/, "") end
Source
# File lib/clock/condense.rb, line 53 def redundant_led?(led_lines, time_label) label = time_label.to_s.strip return false if label.empty? led_lines.length == 1 && led_lines.first.to_s.strip == label end
Source
# File lib/clock/condense.rb, line 31 def tick_body_lines(led_lines:, association_lines:, time_label: nil) led = Array(led_lines).map(&:to_s).reject(&:empty?) assoc = Array(association_lines) .first(MAX_ASSOCIATION_LINES) .map { |line| condense_line(line) } .reject(&:empty?) if redundant_led?(led, time_label) && !assoc.empty? assoc else led.map { |line| condense_line(line) } + assoc end end
Source
# File lib/clock/condense.rb, line 24 def tick_led_body_lines(led_lines:, time_label: nil) led = Array(led_lines).map(&:to_s).reject(&:empty?) return [] if redundant_led?(led, time_label) led.map { |line| condense_line(line) } end