Sha256: 56d518c923f515b71d828d018232e7ab86f7b3bfeb720945e7d91dbb10e3e615

Contents?: true

Size: 729 Bytes

Versions: 4

Compression:

Stored size: 729 Bytes

Contents

module Danica
  class Variable
    include ActiveModel::Model
    attr_accessor :value, :name, :latex, :gnu

    def to_f
      value.nil? ? raise(Exception::NotDefined) : value.to_f
    end

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

    def to_tex
      return value.to_tex if value
      (latex || name).to_s
    end

    def to_gnu
      return value.to_gnu if value
      (gnu || name).to_s
    end

    def valued?
      value.present?
    end

    def value=(value)
      @value = value.is_a?(Numeric) ? Number.new(value) : value
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
danica-2.0.1 lib/danica/variable.rb
danica-2.0.0 lib/danica/variable.rb
danica-1.2.0 lib/danica/variable.rb
danica-1.1.0 lib/danica/variable.rb