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
  prefix_instance.base
end

#idObject



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

def id
  @prefix.id
end

#nameObject



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

def name
  prefix_instance.name
end

#powerObject



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

def power
  prefix_instance.power
end

#prefix_instanceObject



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

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

#prefixes_symbolsObject



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

def prefixes_symbols
  prefix_instance.symbol
end

#symbolidObject



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

def symbolid
  prefixes_symbols.ascii if prefixes_symbols
end

#to_asciimath(_) ⇒ Object



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

def to_asciimath(_)
  prefixes_symbols.ascii
end

#to_html(_) ⇒ Object



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

def to_html(_)
  prefixes_symbols.html
end

#to_latex(_) ⇒ Object



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

def to_latex(_)
  prefixes_symbols.latex
end

#to_mathml(_) ⇒ Object



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

  { method_name: :mi, value: ::Mml::Mi.new(value: symbol)}
end

#to_unicode(_) ⇒ Object



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

def to_unicode(_)
  prefixes_symbols.unicode
end