227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
# File 'lib/unitsml/utility.rb', line 227
def prefixes(units, options)
uniq_prefixes = units.map { |unit| unit.prefix }.compact.uniq { |d| d.prefix_name }
uniq_prefixes.map do |prefix|
prefix_attrs = { prefix_base: prefix&.base, prefix_power: prefix&.power, id: prefix&.id }
type_and_methods = { ASCII: :to_asciimath, unicode: :to_unicode, LaTeX: :to_latex, HTML: :to_html }
prefix_attrs[:name] = Model::Prefixes::Name.new(content: prefix&.name)
prefix_attrs[:symbol] = type_and_methods.map do |type, method_name|
Model::Prefixes::Symbol.new(
type: type,
content: prefix&.public_send(method_name, options),
)
end
Model::Prefix.new(prefix_attrs).to_xml.gsub("&", "&")
end.join("\n")
end
|