Sha256: 4724ce63da62100a909dc1d3d64c52519a0b11bf5220774a7265a89725b7f622

Contents?: true

Size: 968 Bytes

Versions: 1

Compression:

Stored size: 968 Bytes

Contents

module Checked
class Demand
module Mods
module Strings
    
  def self.before_apply d
  end

  def self.apply? d
    d.target.is_a?( String ) ||
      d.target.is_a?(StringIO)
  end
  
  def self.after_apply d
    if d.target.is_a?(StringIO)
      d.target.rewind
      d.target= d.target.readlines
      d.target.rewind
    end
  end

  def include! matcher
    included = target[matcher]
    return true if included
    fail!("...must contain: #{matcher.inspect}")
  end

  def exclude! matcher
    raise_e = val[matcher]
    return true unless raise_e
    fail!("...can't contain #{matcher.inspect}")
  end

  def matches_only! matcher
      str = target.gsub(matcher, '')
      if !str.empty?
        fail!( "...has invalid characters: #{str.inspect}" ) 
      end
  end

  def not_empty!
    if target.strip.empty? 
      fail!("...can't be empty.") 
    end
  end
  
end # === module Strings
end # === module DSL
end # === class Demand
end # === module Checked

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
Checked-0.1.4 lib/Checked/Demand/Mods/Strings.rb