Sha256: c788107d32d7a75171a8fc9f91fe2b11c964355c999ef4e922be74349ce1e53e

Contents?: true

Size: 1019 Bytes

Versions: 9

Compression:

Stored size: 1019 Bytes

Contents

module Danica
  class Wrapper::Constant
    include BaseOperations
    include Common

    attr_reader :value, :latex, :gnu

    default_value :priority, 10
    default_value :valued?, true
    default_value :is_grouped?, false
    default_value :constant?, true

    def initialize(*args)
      attrs = args.extract_options!
      attrs = args.as_hash(%i(value latex gnu)).merge(attrs)

      attrs.each do |key, value|
        self.send("#{key}=", value)
      end
    end

    def to_f
      value.to_f
    end

    def ==(other)
      return false unless other.class == self.class
      gnu == other.gnu && latex == other.latex && value == other.value
    end

    def to_tex
      latex.to_s
    end

    def to_gnu
      gnu.to_s
    end

    private

    def value=(value)
      @value = value
    end

    def latex=(latex)
      @latex = latex
    end

    def gnu=(gnu)
      @gnu = gnu
    end
  end

  E = Wrapper::Constant.new(Math::E, :e, 'exp(1)')
  PI = Wrapper::Constant.new(Math::PI, '\pi', :pi)
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
danica-2.6.4 lib/danica/wrapper/constant.rb
danica-2.6.3 lib/danica/wrapper/constant.rb
danica-2.6.2 lib/danica/wrapper/constant.rb
danica-2.6.1 lib/danica/wrapper/constant.rb
danica-2.6.0 lib/danica/wrapper/constant.rb
danica-2.5.1 lib/danica/wrapper/constant.rb
danica-2.5.0 lib/danica/wrapper/constant.rb
danica-2.4.4 lib/danica/wrapper/constant.rb
danica-2.4.3 lib/danica/wrapper/constant.rb