Class: Unitsml::Prefix

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix_name, only_instance = false) ⇒ Prefix

Returns a new instance of Prefix.



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

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.



5
6
7
# File 'lib/unitsml/prefix.rb', line 5

def only_instance
  @only_instance
end

#prefix_nameObject

Returns the value of attribute prefix_name.



5
6
7
# File 'lib/unitsml/prefix.rb', line 5

def prefix_name
  @prefix_name
end

Instance Method Details

#==(object) ⇒ Object



12
13
14
15
16
# File 'lib/unitsml/prefix.rb', line 12

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

#baseObject



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

def base
  fields&.dig("base")
end

#fieldsObject



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

def fields
  Unitsdb.prefixes_hash.dig(prefix_name, :fields)
end

#idObject



18
19
20
# File 'lib/unitsml/prefix.rb', line 18

def id
  Unitsdb.prefixes_hash.dig(prefix_name, :id)
end

#nameObject



22
23
24
# File 'lib/unitsml/prefix.rb', line 22

def name
  fields.dig("name")
end

#powerObject



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

def power
  fields&.dig("power")
end

#prefixes_symbolsObject



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

def prefixes_symbols
  fields&.dig("symbol")
end

#symbolidObject



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

def symbolid
  prefixes_symbols["ascii"] if prefixes_symbols
end

#to_asciimathObject



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

def to_asciimath
  prefixes_symbols["ascii"]
end

#to_htmlObject



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

def to_html
  prefixes_symbols["html"]
end

#to_latexObject



45
46
47
# File 'lib/unitsml/prefix.rb', line 45

def to_latex
  prefixes_symbols["latex"]
end

#to_mathmlObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/unitsml/prefix.rb', line 34

def to_mathml
  symbol = Utility.string_to_html_entity(
    Utility.html_entity_to_unicode(
      prefixes_symbols["html"]
    ),
  )
  return symbol unless only_instance

  Utility.ox_element("mi") << symbol
end

#to_unicodeObject



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

def to_unicode
  prefixes_symbols["unicode"]
end