Sha256: b94144e7dd72db18bae22fad3948d020531e73a2ff5464e57f3a7e9c537afc96

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Danica
  class Wrapper::Variable
    include BaseOperations
    include Common

    attr_accessor :name, :latex, :gnuplot
    attr_reader :value

    default_value :priority,    10
    default_value :is_grouped?, false
    default_value :variable?,   true

    def initialize(*args)
      attrs = args.extract_options!
      attrs = args.as_hash(%i[name value latex gnuplot]).merge(attrs)

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

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

    def ==(other)
      return false unless other.class == self.class

      other.value == value &&
        other.name == name &&
        other.latex == latex &&
        other.gnuplot == gnuplot
    end

    def to_tex(**options)
      return value.to_tex(options) if value

      (latex || name).to_s
    end

    def to_gnu(**options)
      return value.to_gnu(options) if value

      (gnuplot || name).to_s
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
danica-2.7.7 lib/danica/wrapper/variable.rb
danica-2.7.6 lib/danica/wrapper/variable.rb