module SheepAst::DataHandle

This module is used to handle AnalyzeData bject

Public Instance Methods

data_handle_init(exprs, **options) click to toggle source
# File lib/sheep_ast/data_handle_util.rb, line 159
def data_handle_init(exprs, **options)
  @exprs = exprs.is_a?(Enumerable) ? exprs : [exprs]
  offset = options[:offset]
  offset_line = options[:line_offset]
  @include_newline = options[:includ_newline]
  @offset = offset.nil? ? 1 : offset
  @offset_line = offset_line.nil? ? 0 : offset_line
end
validate(data) click to toggle source
# File lib/sheep_ast/data_handle_util.rb, line 169
def validate(data)
  @exprs.each_with_index do |expr, idx|
    idata = index_data(data, @offset_line, @offset + idx, @include_newline)
    if !match_dh(expr, T.must(idata))
      ldebug? and ldebug "validate fail: #{expr} is not hit for #{idata}"
      return false
    else
      ldebug? and ldebug "validte ok: #{expr}"
    end
  end
  return true
end

Private Instance Methods

match_dh(expr1, expr2) click to toggle source
# File lib/sheep_ast/data_handle_util.rb, line 185
def match_dh(expr1, expr2)
  if expr1.instance_of? String
    if expr1 == expr2
      return true
    else
      return false
    end
  else
    if expr1 =~ expr2
      return true
    else
      return false
    end
  end
end