Sha256: 1b98b3031e7d9a03fa00228d712d4a192821ebe2b5bc72b95fb32eb4f44963dd

Contents?: true

Size: 1.08 KB

Versions: 4

Compression:

Stored size: 1.08 KB

Contents

module Danica
  class Wrapper::Variable
    include BaseOperations
    include Common

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

    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|
        self.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
      return 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

4 entries across 4 versions & 1 rubygems

Version Path
danica-2.7.4 lib/danica/wrapper/variable.rb
danica-2.7.3 lib/danica/wrapper/variable.rb
danica-2.7.2 lib/danica/wrapper/variable.rb
danica-2.7.1 lib/danica/wrapper/variable.rb