51 lines
1.1 KiB
Ruby
51 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Repubmark
|
|
module Elems
|
|
class Abbrev < Base
|
|
parents :Joint
|
|
|
|
attr_reader :abbrev, :transcript
|
|
|
|
def initialize(parent, abbrev, transcript)
|
|
super parent
|
|
|
|
self.abbrev = abbrev
|
|
self.transcript = transcript
|
|
end
|
|
|
|
#################
|
|
# Basic methods #
|
|
#################
|
|
|
|
def word_count = 1
|
|
|
|
def to_html
|
|
%(<abbr title="#{escape_transcript}">#{escape_abbrev}</abbr>).freeze
|
|
end
|
|
|
|
def to_gemtext = abbrev
|
|
|
|
private
|
|
|
|
def abbrev=(abbrev)
|
|
@abbrev =
|
|
String(abbrev).split.join(' ').freeze.tap do |new_abbrev|
|
|
raise 'Empty string' if new_abbrev.empty?
|
|
end
|
|
end
|
|
|
|
def transcript=(transcript)
|
|
@transcript =
|
|
String(transcript).split.join(' ').freeze.tap do |new_transcript|
|
|
raise 'Empty string' if new_transcript.empty?
|
|
end
|
|
end
|
|
|
|
def escape_abbrev = CGI.escape_html(abbrev).freeze
|
|
|
|
def escape_transcript = CGI.escape_html(transcript).freeze
|
|
end
|
|
end
|
|
end
|