module SingFormat
Constants
- CHUNK_HELPER
- IRC_CTRL
Public Instance Methods
Source
# File lib/sing_format.rb, line 30 def filter_script_lines(lines) lines.reject { |line| script_line?(line) } end
Source
# File lib/sing_format.rb, line 60 def format_lyric_lines(lyrics) lines = merge_lyric_lines(normalize_lyrics(lyrics).split("\n")) return "" if lines.empty? lines.join("\n") end
Source
# File lib/sing_format.rb, line 85 def format_lyrics(artist, title, lyrics) body = format_lyric_lines(lyrics) return NO_LYRICS_MESSAGE if body.empty? "#{artist.to_s.strip} — #{title.to_s.strip}:\n#{body}" end
Source
# File lib/sing_format.rb, line 39 def merge_lyric_lines(lines, max_chars: MAX_LYRIC_LINE_CHARS) cleaned = lines.map(&:to_s).map(&:strip).reject(&:empty?) return [] if cleaned.empty? merged = [] current = +cleaned.first cleaned.drop(1).each do |line| candidate = "#{current} #{line}" if current.length >= BASE_MAX_LYRIC_LINE_CHARS && candidate.length <= max_chars current = candidate else merged << current current = +line end end merged << current merged end
Source
# File lib/sing_format.rb, line 34 def normalize_lyrics(text) lines = text.to_s.strip.gsub(/\n{2,}/, "\n").gsub(/[ \t]+\n/, "\n").split("\n") filter_script_lines(lines).map(&:rstrip).reject(&:empty?).join("\n") end
Source
# File lib/sing_format.rb, line 71 def reply_pieces(text, message:, outgoing_line_limit:, chunker: CHUNK_HELPER.method(:chunk_text)) limit = scaled_line_byte_limit(outgoing_line_limit) pieces = [] text.to_s.split("\n").each do |line| line = line.rstrip next if line.empty? pieces.concat(chunker.call(line, max_bytes: limit)) end pieces end
Source
# File lib/sing_format.rb, line 67 def scaled_line_byte_limit(base_limit) (base_limit.to_f * LINE_LENGTH_FACTOR).floor end
Source
# File lib/sing_format.rb, line 23 def script_line?(line) text = line.to_s.strip return false if text.empty? text.match?(SCRIPT_LINE_PATTERN) || text.include?(IRC_CTRL) end