32 lines
634 B
Ruby
32 lines
634 B
Ruby
|
# frozen_string_literal: true
|
||
|
|
||
|
module Repubmark
|
||
|
module Elems
|
||
|
class Fraction < Base
|
||
|
parents :Joint
|
||
|
|
||
|
def initialize(parent, top, bottom)
|
||
|
super parent
|
||
|
|
||
|
@top = Integer top
|
||
|
@bottom = Integer bottom
|
||
|
|
||
|
raise 'Expected top to be non-negative' if @top.negative?
|
||
|
raise 'Expected bottom to be positive' unless @bottom.positive?
|
||
|
end
|
||
|
|
||
|
#################
|
||
|
# Basic methods #
|
||
|
#################
|
||
|
|
||
|
def word_count = 1
|
||
|
|
||
|
def to_html
|
||
|
"<sup>#@top</sup>⁄<sub>#@bottom</sub>".freeze
|
||
|
end
|
||
|
|
||
|
def to_gemtext = "#@top/#@bottom"
|
||
|
end
|
||
|
end
|
||
|
end
|