Class: Giter8::Conditional
- Inherits:
-
Object
- Object
- Giter8::Conditional
- Defined in:
- lib/giter8/conditional.rb
Overview
Represents a conditional structure in an AST
Constant Summary collapse
- TRUTHY_VALUES =
%w[yes y true].freeze
Instance Attribute Summary collapse
-
#column ⇒ Object
Returns the value of attribute column.
-
#cond_else ⇒ Object
Returns the value of attribute cond_else.
-
#cond_else_if ⇒ Object
Returns the value of attribute cond_else_if.
-
#cond_then ⇒ Object
Returns the value of attribute cond_then.
-
#helper ⇒ Object
Returns the value of attribute helper.
-
#line ⇒ Object
Returns the value of attribute line.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#property ⇒ Object
Returns the value of attribute property.
-
#source ⇒ Object
Returns the value of attribute source.
Class Method Summary collapse
-
.truthy?(value) ⇒ Boolean
Returns whether a provided value is considered as “truthy”.
Instance Method Summary collapse
-
#clean ⇒ Object
Cleans this Conditional’s branches by calling AST#clean, and returns a copy of this instance.
-
#clean! ⇒ Object
clean! executes the same operation as #clean, but updates this instance instead of returning a copy.
-
#initialize(property, helper, parent, source, line, column) ⇒ Conditional
constructor
A new instance of Conditional.
Constructor Details
#initialize(property, helper, parent, source, line, column) ⇒ Conditional
Returns a new instance of Conditional.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/giter8/conditional.rb', line 24 def initialize(property, helper, parent, source, line, column) @source = source @line = line @column = column @property = property @helper = helper @parent = parent @cond_then = AST.new @cond_else_if = AST.new @cond_else = AST.new end |
Instance Attribute Details
#column ⇒ Object
Returns the value of attribute column.
6 7 8 |
# File 'lib/giter8/conditional.rb', line 6 def column @column end |
#cond_else ⇒ Object
Returns the value of attribute cond_else.
6 7 8 |
# File 'lib/giter8/conditional.rb', line 6 def cond_else @cond_else end |
#cond_else_if ⇒ Object
Returns the value of attribute cond_else_if.
6 7 8 |
# File 'lib/giter8/conditional.rb', line 6 def cond_else_if @cond_else_if end |
#cond_then ⇒ Object
Returns the value of attribute cond_then.
6 7 8 |
# File 'lib/giter8/conditional.rb', line 6 def cond_then @cond_then end |
#helper ⇒ Object
Returns the value of attribute helper.
6 7 8 |
# File 'lib/giter8/conditional.rb', line 6 def helper @helper end |
#line ⇒ Object
Returns the value of attribute line.
6 7 8 |
# File 'lib/giter8/conditional.rb', line 6 def line @line end |
#parent ⇒ Object
Returns the value of attribute parent.
6 7 8 |
# File 'lib/giter8/conditional.rb', line 6 def parent @parent end |
#property ⇒ Object
Returns the value of attribute property.
6 7 8 |
# File 'lib/giter8/conditional.rb', line 6 def property @property end |
#source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/giter8/conditional.rb', line 6 def source @source end |
Class Method Details
.truthy?(value) ⇒ Boolean
Returns whether a provided value is considered as “truthy”. Giter8 assumes the values “yes”, “y”, and “true” as true. Any other value is assumed to be false.
14 15 16 17 18 19 20 21 22 |
# File 'lib/giter8/conditional.rb', line 14 def self.truthy?(value) if value.nil? nil elsif value.is_a? Literal truthy?(value.value) elsif value.is_a? String TRUTHY_VALUES.any? { |e| e.casecmp(value).zero? } end end |
Instance Method Details
#clean ⇒ Object
Cleans this Conditional’s branches by calling AST#clean, and returns a copy of this instance.
39 40 41 42 43 44 45 46 47 |
# File 'lib/giter8/conditional.rb', line 39 def clean cond = Conditional.new(@property, @helper, @parent, @source, @line, @column) cond.cond_then = @cond_then.clean cond.cond_else = @cond_else.clean cond.cond_else_if = @cond_else_if.clean cond end |
#clean! ⇒ Object
clean! executes the same operation as #clean, but updates this instance instead of returning a copy.
51 52 53 54 55 |
# File 'lib/giter8/conditional.rb', line 51 def clean! @cond_then = @cond_then.clean @cond_else = @cond_else.clean @cond_else_if = @cond_else_if.clean end |