class Modelling::Parameter

Parameter class

Attributes

description[RW]
name[RW]
value[RW]

Public Class Methods

new(name = nil, value = nil, desc = nil) click to toggle source
# File lib/modelling/parameter.rb, line 12
def initialize(name = nil, value = nil, desc = nil)
    @name = name || "parameter_#{@@insts}"
    @value = (value || "0.0").to_f
    @description = desc || ""
    @@insts = @@insts + 1
end

Public Instance Methods

from_par(str) click to toggle source

initialize from a line in a sassy par file

Example:

Parameter.new.to_par("k  1  \"The value of parameter k\"").to_s

gives

  Parameter 'k' = 1 (The value of parameter k)
# File lib/modelling/parameter.rb, line 29
def from_par(str)
    pa = str.split(/\s+/)
    if pa.length < 2
        raise "Failed to create a parameter from input."
    end
    @name = pa[0]
    @value = pa[1].to_f
    @description = str.sub(/\s*[^\s]+\s+[^\s]+\s*/, "").sub(/^[\"']+\s*/, "").sub(/\s*[\"']+$/, "") || ""
end
to_par() click to toggle source

Make a parameter line

# File lib/modelling/parameter.rb, line 48
def to_par
    "#{@name}    #{@value}   \"#{@description}\"\n"
end
to_s() click to toggle source

Make a string

# File lib/modelling/parameter.rb, line 53
def to_s
    "Parameter '#{@name}' = #{@value} " + (@description.length > 0 ? "(#{@description})" : "")
end
to_sbml() click to toggle source

Return the parameter as an XML node

# File lib/modelling/parameter.rb, line 40
def to_sbml
    e = REXML::Element::new 'parameter'
    e.add_attribute('name', @name)
    e.add_attribute('value', @value)
    e
end