Class: Plotty::Function
- Inherits:
-
Struct
- Object
- Struct
- Plotty::Function
- Defined in:
- lib/plotty/graph.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command
60 61 62 |
# File 'lib/plotty/graph.rb', line 60 def command @command end |
#pattern ⇒ Object
Returns the value of attribute pattern
60 61 62 |
# File 'lib/plotty/graph.rb', line 60 def pattern @pattern end |
#title ⇒ Object
Returns the value of attribute title
60 61 62 |
# File 'lib/plotty/graph.rb', line 60 def title @title end |
Class Method Details
.parse(pattern, command) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/plotty/graph.rb', line 61 def self.parse(pattern, command) pattern = Regexp.new(pattern, Regexp::MULTILINE) if command =~ /^(\w+):(.*?)$/ self.new(pattern, $2, $1) else self.new(pattern, command, command) end end |
Instance Method Details
#call(value) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/plotty/graph.rb', line 71 def call(value) r, w = IO.pipe $stderr.puts "Running #{self.command} with x = #{value}..." pid = Process.spawn({'x' => value.to_s}, self.command, out: w, err: STDERR) w.close buffer = r.read Process.waitpid pid if match = self.pattern.match(buffer) $stderr.puts "\tresult = #{match.inspect}" if match.captures.empty? return [match[0]] else return match.captures end end end |