Module: Tool

Defined in:
lib/linmeric/CnGal_tools.rb

Overview

Provides some useful procedure for linmeric

Author

Massimiliano Dal Mas ([email protected])

License

Distributed under MIT license

Class Method Summary collapse

Class Method Details

.fObject

returns: array of the supported math functions; see: Function



29
30
31
# File 'lib/linmeric/CnGal_tools.rb', line 29

def self.f
  return ["log","sin","cos","PI","tan","exp"]
end

.is_exp?(str) ⇒ Boolean

Dummy function to ckeck if a string represents an expression (may not work properly)

  • argument: string to be checked

  • returns: true if ‘str` represents an expression; false else.

Returns:

  • (Boolean)


45
46
47
48
# File 'lib/linmeric/CnGal_tools.rb', line 45

def self.is_exp?(str)
  (str.contain? "=+*-/^") ? (return true) : (('0123456789.'.contain_all? str) ? 
  (return true):((self.letters.contain? str) ? (return true):(return false)))
end

.is_keyword?(ob) ⇒ Boolean

Checks if a string represents a keyword

  • argument: object to check

  • returns: true if ‘ob` represents a keyword; false else.

Returns:

  • (Boolean)


37
38
39
# File 'lib/linmeric/CnGal_tools.rb', line 37

def self.is_keyword?(ob)   
  (self.keys.include? ob) ? (return true) : (return false)
end

.keysObject

  • returns: array of all the keywords used by linmeric



14
15
16
# File 'lib/linmeric/CnGal_tools.rb', line 14

def self.keys 
  return ["mx:","t:", "shw:","shwvar:","det:","solve:","from:","as:","f:","norm:","id_mx:","integ:"]
end

.lettersObject

  • returns: alphabet in string format



24
25
26
# File 'lib/linmeric/CnGal_tools.rb', line 24

def self.letters
  return "abcdefghijklmnopqrstuvwxyz"
end

.operatorsObject

  • returns: array of all the operators



19
20
21
# File 'lib/linmeric/CnGal_tools.rb', line 19

def self.operators
  return ["=","-","+","*","/","^",">"]
end

Prints the hash of the variables

  • argument: hash to be printed



53
54
55
56
57
58
59
# File 'lib/linmeric/CnGal_tools.rb', line 53

def self.print_stack(stack)
  stack.keys.each do |k|
    puts "#{k} = " if stack[k].is_a? Matrix
    print "#{k} = " unless stack[k].is_a? Matrix
    puts stack[k]
  end
end