Class: DRG::Ruby::Condition
- Inherits:
-
Object
- Object
- DRG::Ruby::Condition
- Defined in:
- lib/drg/ruby/condition.rb
Instance Attribute Summary collapse
-
#nested_conditions ⇒ Object
readonly
Returns the value of attribute nested_conditions.
-
#sexp ⇒ Object
readonly
Returns the value of attribute sexp.
-
#statement ⇒ Object
readonly
Returns the value of attribute statement.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
Set related stuff.
- #hash ⇒ Object
-
#initialize(sexp) ⇒ Condition
constructor
A new instance of Condition.
- #return_value ⇒ Object
- #short_statement ⇒ Object
- #translate(txt) ⇒ Object
Constructor Details
#initialize(sexp) ⇒ Condition
Returns a new instance of Condition.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/drg/ruby/condition.rb', line 7 def initialize(sexp) @sexp = sexp @statement = Ruby2Ruby.new.process(sexp.deep_clone) @nested_conditions = Set.new sexp.drop(1).flatten.include?(:if) && sexp.drop(1).deep_each do |exp| DRG::Decorators::SexpDecorator.new(exp).each_sexp_condition do |node| @nested_conditions << self.class.new(node) end end @nested_conditions = @nested_conditions.to_a end |
Instance Attribute Details
#nested_conditions ⇒ Object (readonly)
Returns the value of attribute nested_conditions.
5 6 7 |
# File 'lib/drg/ruby/condition.rb', line 5 def nested_conditions @nested_conditions end |
#sexp ⇒ Object (readonly)
Returns the value of attribute sexp.
5 6 7 |
# File 'lib/drg/ruby/condition.rb', line 5 def sexp @sexp end |
#statement ⇒ Object (readonly)
Returns the value of attribute statement.
5 6 7 |
# File 'lib/drg/ruby/condition.rb', line 5 def statement @statement end |
Instance Method Details
#eql?(other) ⇒ Boolean
Set related stuff
45 46 47 |
# File 'lib/drg/ruby/condition.rb', line 45 def eql?(other) hash == other.hash end |
#hash ⇒ Object
49 50 51 |
# File 'lib/drg/ruby/condition.rb', line 49 def hash sexp.object_id end |
#return_value ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/drg/ruby/condition.rb', line 27 def return_value if @statement =~ /\s+\?\s+(.*?)(:|$)/ $1.strip else translate @statement[/(.*?)(unless|if)/, 1].to_s.strip end end |
#short_statement ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/drg/ruby/condition.rb', line 19 def short_statement if @statement =~ /(unless|if)(.+)$/ ($1 << $2).strip elsif @statement =~ /(.*?)\s+\?\s+/ $1.strip end end |
#translate(txt) ⇒ Object
35 36 37 38 39 |
# File 'lib/drg/ruby/condition.rb', line 35 def translate(txt) txt.sub! /^return\s*/, 'returns ' txt.sub! /^returns\s*$/, 'returns nil' txt.strip end |