Class: Unitsml::Prefix

Inherits:
Object
  • Object
show all
Includes:
MathmlHelper
Defined in:
lib/unitsml/prefix.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from MathmlHelper

coerce_mml_v4_collection_attributes!, coerce_mml_v4_collection_value, mml_v4_class_for, mml_v4_content_attribute, mml_v4_context, mml_v4_from_xml, mml_v4_new, mml_v4_with_content

Constructor Details

#initialize(prefix_name, only_instance = false) ⇒ Prefix

Returns a new instance of Prefix.



9
10
11
12
# File 'lib/unitsml/prefix.rb', line 9

def initialize(prefix_name, only_instance = false)
  @prefix_name = prefix_name
  @only_instance = only_instance
end

Instance Attribute Details

#only_instanceObject

Returns the value of attribute only_instance.



7
8
9
# File 'lib/unitsml/prefix.rb', line 7

def only_instance
  @only_instance
end

#prefix_nameObject

Returns the value of attribute prefix_name.



7
8
9
# File 'lib/unitsml/prefix.rb', line 7

def prefix_name
  @prefix_name
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
17
18
# File 'lib/unitsml/prefix.rb', line 14

def ==(other)
  self.class == other.class &&
    prefix_name == other&.prefix_name &&
    only_instance == other&.only_instance
end

#baseObject



69
70
71
# File 'lib/unitsml/prefix.rb', line 69

def base
  prefix_instance.base
end

#idObject



24
25
26
27
28
# File 'lib/unitsml/prefix.rb', line 24

def id
  @id ||= prefix_instance.identifiers.find do |prefix|
    prefix.type == "nist"
  end&.id
end

#nameObject



30
31
32
# File 'lib/unitsml/prefix.rb', line 30

def name
  @name ||= prefix_instance.names.find { |name| name.lang == "en" }.value
end

#powerObject



73
74
75
# File 'lib/unitsml/prefix.rb', line 73

def power
  prefix_instance.power
end

#prefix_instanceObject



20
21
22
# File 'lib/unitsml/prefix.rb', line 20

def prefix_instance
  @prefix_instance ||= Unitsdb.prefixes.find_by_symbol_name(prefix_name)
end

#prefix_symbolsObject



34
35
36
# File 'lib/unitsml/prefix.rb', line 34

def prefix_symbols
  prefix_instance.symbols.last
end

#symbolidObject



65
66
67
# File 'lib/unitsml/prefix.rb', line 65

def symbolid
  prefix_symbols&.ascii
end

#to_asciimath(_) ⇒ Object



53
54
55
# File 'lib/unitsml/prefix.rb', line 53

def to_asciimath(_)
  prefix_symbols.ascii
end

#to_html(_) ⇒ Object



57
58
59
# File 'lib/unitsml/prefix.rb', line 57

def to_html(_)
  prefix_symbols.html
end

#to_latex(_) ⇒ Object



49
50
51
# File 'lib/unitsml/prefix.rb', line 49

def to_latex(_)
  prefix_symbols.latex
end

#to_mathml(_) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/unitsml/prefix.rb', line 38

def to_mathml(_)
  symbol = Utility.string_to_html_entity(
    Utility.html_entity_to_unicode(
      prefix_symbols.html,
    ),
  )
  return symbol unless only_instance

  { method_name: :mi, value: mml_v4_new(:mi, value: symbol) }
end

#to_unicode(_) ⇒ Object



61
62
63
# File 'lib/unitsml/prefix.rb', line 61

def to_unicode(_)
  prefix_symbols.unicode
end