Module: Operator
- Defined in:
- lib/re_duxml/evaluate/operator.rb
Overview
Copyright © 2016 Freescale Semiconductor Inc.
Instance Method Summary collapse
-
#arity ⇒ Fixnum
Number of arguments required.
- #grouping? ⇒ Boolean
- #inverse ⇒ Object
- #pair ⇒ Object
- #parent=(logic) ⇒ Object
-
#position ⇒ Symbol
:prefix, :infix (default), or :postfix.
- #print ⇒ Object
-
#regexp ⇒ Regexp
Expression to find operator in string.
- #reverse ⇒ Object
- #right_associative? ⇒ Boolean
-
#ruby ⇒ String
Name of ruby method corresponding to this operator.
-
#symbol ⇒ String
Literal for operator e.g.
- #to_s ⇒ Object
Instance Method Details
#arity ⇒ Fixnum
Returns number of arguments required.
90 91 92 93 94 95 |
# File 'lib/re_duxml/evaluate/operator.rb', line 90 def arity nodes.find do |n| return n.text.to_i if n.name == 'arity' end 2 end |
#grouping? ⇒ Boolean
4 5 6 7 8 9 |
# File 'lib/re_duxml/evaluate/operator.rb', line 4 def grouping? nodes.find do |n| return true if n.name == 'pair' end false end |
#inverse ⇒ Object
63 64 65 66 67 68 |
# File 'lib/re_duxml/evaluate/operator.rb', line 63 def inverse nodes.find do |n| return @logic[n.text] if n.name == 'inverse' end nil end |
#pair ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/re_duxml/evaluate/operator.rb', line 55 def pair return nil unless grouping? nodes.find do |n| return @logic[n.text] if n.name == 'pair' end raise Exception end |
#parent=(logic) ⇒ Object
11 12 13 |
# File 'lib/re_duxml/evaluate/operator.rb', line 11 def parent=(logic) @logic = logic end |
#position ⇒ Symbol
Returns :prefix, :infix (default), or :postfix.
41 42 43 44 45 46 |
# File 'lib/re_duxml/evaluate/operator.rb', line 41 def position nodes.find do |n| return n.text.to_sym if n.name == 'position' end :infix end |
#print ⇒ Object
74 75 76 77 78 79 |
# File 'lib/re_duxml/evaluate/operator.rb', line 74 def print nodes.find do |n| return n.text if n.name == 'print' end symbol end |
#regexp ⇒ Regexp
Returns expression to find operator in string.
82 83 84 85 86 87 |
# File 'lib/re_duxml/evaluate/operator.rb', line 82 def regexp nodes.find do |n| return Regexp.new(n.text) if %w(regexp symbol ).include?(n.name) end # TODO exception here? end |
#reverse ⇒ Object
48 49 50 51 52 53 |
# File 'lib/re_duxml/evaluate/operator.rb', line 48 def reverse nodes.find do |n| return @logic[n.text] if n.name == 'reverse' end nil end |
#right_associative? ⇒ Boolean
16 17 18 19 20 21 |
# File 'lib/re_duxml/evaluate/operator.rb', line 16 def right_associative? nodes.find do |n| return n.text == 'true' if n.name == 'right_associative' end false end |
#ruby ⇒ String
Returns name of ruby method corresponding to this operator.
24 25 26 27 28 29 |
# File 'lib/re_duxml/evaluate/operator.rb', line 24 def ruby nodes.find do |n| return n.text if n.name == 'ruby' end symbol end |
#symbol ⇒ String
Returns literal for operator e.g. ‘+’.
32 33 34 35 36 37 38 |
# File 'lib/re_duxml/evaluate/operator.rb', line 32 def symbol return nil unless self.respond_to?(:nodes) nodes.find do |n| return n.text if n.name == 'symbol' end raise Exception end |
#to_s ⇒ Object
70 71 72 |
# File 'lib/re_duxml/evaluate/operator.rb', line 70 def to_s symbol end |