Sha256: 44807e780b204c60cd9171ba6f1df6f698adb32c1391992fbcc2f884813fc140

Contents?: true

Size: 1012 Bytes

Versions: 8

Compression:

Stored size: 1012 Bytes

Contents

# frozen_string_literal: true

module Unitsml
  class Prefix
    attr_accessor :prefix_name

    def initialize(prefix_name)
      @prefix_name = prefix_name
    end

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

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

    def name
      fields.dig("name")
    end

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

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

    def to_mathml
      prefixes_symbols["html"]
    end

    def to_latex
      prefixes_symbols["latex"]
    end

    def to_asciimath
      prefixes_symbols["ascii"]
    end

    def to_html
      prefixes_symbols["html"]
    end

    def to_unicode
      prefixes_symbols["unicode"]
    end

    def symbolid
      prefixes_symbols["ascii"] if prefixes_symbols
    end

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

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
unitsml-0.2.7 lib/unitsml/prefix.rb
unitsml-0.2.6 lib/unitsml/prefix.rb
unitsml-0.2.5 lib/unitsml/prefix.rb
unitsml-0.2.4 lib/unitsml/prefix.rb
unitsml-0.2.3 lib/unitsml/prefix.rb
unitsml-0.2.2 lib/unitsml/prefix.rb
unitsml-0.2.1 lib/unitsml/prefix.rb
unitsml-0.2.0 lib/unitsml/prefix.rb