class Sheng::ConditionalBlock

Public Instance Methods

conditional_type() click to toggle source
# File lib/sheng/conditional_block.rb, line 17
def conditional_type
  @start_field.block_prefix
end
criterion_met?(variable) click to toggle source
# File lib/sheng/conditional_block.rb, line 21
def criterion_met?(variable)
  variable_exists = variable && (variable == true || !variable.empty?)
  if conditional_type == "if"
    variable_exists
  else
    !variable_exists
  end
end
interpolate(data_set) click to toggle source
# File lib/sheng/conditional_block.rb, line 5
def interpolate(data_set)
  variable = data_set.fetch(key, :default => nil)
  @start_field.remove
  @end_field.remove
  if criterion_met?(variable)
    merge_field_set = MergeFieldSet.new("#{conditional_type}_#{key}", xml_fragment)
    merge_field_set.interpolate(data_set)
  else
    xml_fragment.remove
  end
end