package uk.gov.tna.dri.schema

import scalaz._
import Scalaz._
import uk.gov.tna.dri.metadata.Row

case class InRule(inVal: StringProvider) extends Rule {

  override def execute(columnIndex: Int, row: Row, schema: Schema): ValidationNEL[String, Any] = {
    val columnDefinition = schema.columnDefinitions(columnIndex)

    inVal.cellValue(columnIndex, row, schema) match {
      case Left(e) => e.failNel[Any]

      case Right(ruleValue) => {
        val cellValue = row.cells(columnIndex).value

        if (schema.columnDefinitions(columnIndex).contains(IgnoreCase())) {
          if (ruleValue.toLowerCase.contains(cellValue.toLowerCase))
            true.successNel[String]
          else
            s"in: ${ruleValue} fails for line ${row.lineNumber}, column: ${columnDefinition.id}, value: ${cellValue}".failNel[Any]
        } else {
          if (ruleValue.contains(cellValue))
            true.successNel[String]
          else
            s"in: ${ruleValue} fails for line ${row.lineNumber}, column: ${columnDefinition.id}, value: ${cellValue}".failNel[Any]
        }
      }
    }
  }
}
package uk.gov.tna.dri.schema

import scalaz._
import Scalaz._
import uk.gov.tna.dri.metadata.Row

case class InRule(inVal: StringProvider) extends Rule {

  override def execute(columnIndex: Int, row: Row, schema: Schema): ValidationNEL[String, Any] = {
    val columnDefinition = schema.columnDefinitions(columnIndex)

    inVal.cellValue(columnIndex, row, schema) match {
      case Left(e) => e.failNel[Any]

      case Right(ruleValue) => {
        val cellValue = row.cells(columnIndex).value
        val (cv, rv) = if (schema.columnDefinitions(columnIndex).contains(IgnoreCase())) (cellValue.toLowerCase, ruleValue.toLowerCase) else (cellValue, ruleValue)

        if (rv.contains(cv))
          true.successNel[String]
        else
          s"in: ${ruleValue} fails for line ${row.lineNumber}, column: ${columnDefinition.id}, value: ${cellValue}".failNel[Any]
      }
    }
  }
}
Clean up of checking "ignore case", but it is still crap.
 [DA] Clean up of checking "ignore case", but it is still crap.

git-svn-id: d9d935340129e626144eb3fe7cfd050cd27cf88a@4599 6bcde575-cb03-8b4d-b1e0-7a084bef6d9c
