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
58 59 60 |
# File 'lib/plotty/graph.rb', line 58 def command @command end |
#pattern ⇒ Object
Returns the value of attribute pattern
58 59 60 |
# File 'lib/plotty/graph.rb', line 58 def pattern @pattern end |
#title ⇒ Object
Returns the value of attribute title
58 59 60 |
# File 'lib/plotty/graph.rb', line 58 def title @title end |
Class Method Details
.parse(pattern, command) ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/plotty/graph.rb', line 59 def self.parse(pattern, command) pattern = Regexp.new(pattern) if command =~ /^(\w+):(.*?)$/ self.new(pattern, $2, $1) else self.new(pattern, command, command) end end |
Instance Method Details
#call(value) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/plotty/graph.rb', line 69 def call(value) r, w = IO.pipe # puts "Running #{@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) result = match[1] || match[0] # puts "\tresult = #{result}" return result end end |