GithubHelp home page GithubHelp logo

valuedate's Introduction

Valuedate

Validates values using a schema.

Source | RDoc | Metrics

Usage

schema = Valuedate.schema do
  value.is_a(String).equals("test")
end

schema.validate("test") # => true
schema.validate("fail") # => false
schema.validate(23) # => false

deep = Valuedate.schema do
  value.hash(
    :type => value.is_a(String),
    :value => value.hash(
      :src => value.is_a(String),
      :height => optional_value.is_a(Fixnum),
      :width => optional_value.is_a(Fixnum)
    )
  )
end

deep.validate(
  :type => "image",
  :value => {
    :src => "/bold.gif",
    :height => 80,
    :width => 80
  }
) # => true

# :height and width are optional
deep.validate(:type => "image", :value => { :src => "/bold.gif" }) # => true

Matchers

Following matchers are defined:

  • is_a(Class)

  • equals(expected)

  • any(list of validators)

  • in(range, array or anything that responds_to #include?)

  • is { |value| boolean }

  • not { |value| boolean }

Missing matchers?

Use #is and #not:

schema = Valuedate.schema do
  value.hash(
    :array  => value.not { |value| value.empty? },
    :rgb    => value.is { |value| value.size == 3 }
  )
end

schema.validate(:array => [1], :rgb => [1,2,3]) # => true
schema.validate(:array => [1], :rgb => [1,2]) # => false

Defining matchers

Valuedate.matcher(:equals) { |value, expected| value == expected }

Install

git clone ...
rake install

Authors

  • Peter Suschlik

TODO

  • Implement and aggregate errors

valuedate's People

Contributors

splattael avatar

Stargazers

Dennis Treder avatar  avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.