Class: Danica::Wrapper::Variable

Inherits:
Object
  • Object
show all
Includes:
BaseOperations, Common
Defined in:
lib/danica/wrapper/variable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#content, #formatted, #gnu, #tex, #to, #valued?

Methods included from BaseOperations

#*, #**, #+, #-, #-@, #/

Constructor Details

#initialize(*args) ⇒ Variable

Returns a new instance of Variable.



15
16
17
18
19
20
21
22
# File 'lib/danica/wrapper/variable.rb', line 15

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

Instance Attribute Details

#gnuplotObject

Returns the value of attribute gnuplot.



8
9
10
# File 'lib/danica/wrapper/variable.rb', line 8

def gnuplot
  @gnuplot
end

#latexObject

Returns the value of attribute latex.



8
9
10
# File 'lib/danica/wrapper/variable.rb', line 8

def latex
  @latex
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/danica/wrapper/variable.rb', line 8

def name
  @name
end

#valueObject

Returns the value of attribute value.



9
10
11
# File 'lib/danica/wrapper/variable.rb', line 9

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/danica/wrapper/variable.rb', line 28

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

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

#to_fObject



24
25
26
# File 'lib/danica/wrapper/variable.rb', line 24

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

#to_gnu(**options) ⇒ Object



43
44
45
46
47
# File 'lib/danica/wrapper/variable.rb', line 43

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

  (gnuplot || name).to_s
end

#to_tex(**options) ⇒ Object



37
38
39
40
41
# File 'lib/danica/wrapper/variable.rb', line 37

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

  (latex || name).to_s
end