class Giter8::Conditional
Represents a conditional structure in an AST
Constants
- TRUTHY_VALUES
Attributes
column[RW]
cond_else[RW]
cond_else_if[RW]
cond_then[RW]
helper[RW]
line[RW]
parent[RW]
property[RW]
source[RW]
Public Class Methods
new(property, helper, parent, source, line, column)
click to toggle source
# 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
truthy?(value)
click to toggle source
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.
# 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
Public Instance Methods
clean()
click to toggle source
Cleans this Conditional's branches by calling AST#clean
, and returns a copy of this instance.
# 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!()
click to toggle source
clean! executes the same operation as clean
, but updates this instance instead of returning a copy.
# 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