0.01
No commit activity in last 3 years
No release in over 3 years
Completeness is a way to add completeness progress (like in LinkedIn) into your application.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
>= 0

Runtime

 Project Readme

Completeness

Completeness is a way to add completeness progress (like in LinkedIn) into your application.

Installation

Add this line to your application's Gemfile:

gem 'completeness'

And then execute:

$ bundle

Or install it yourself as:

$ gem install completeness

Usage

It's extremely simple. Add Completeness::Model module into your model and define weights for each attribute.

class MyModel < Struct.new(:name, :email, :phone, :desctiption, :dob)
  include Completeness::Model
  
  completeness weight: 20 do
    field :name, required: true
    field :email, weight: 15, required: true
    field :phone, weight: 15
    field :description, weight: 5
    field :dob, weight: 10, check: ->(object, value){ value.is_a?(Date) && value.past? }
  end
end

It will add into your model these methods

  • completeness_spec - this is the Completeness::Specification object which contains all specification for the model. See specification.rb for more details.
  • completed? - it returns true if all required attributes are completely filled, otherwise returns false.
  • completed_percent - it returns percentage of completeness the object. It will be integer value between 0 and 100.
  • completed_weight - it returns summary weight of all attributes what was being completed.

The method completeness can take an options hash. It's default options for all fields what will be defined in the block. Available options are:

  • :weight - default weight.
  • :required - set true if you are going to mark all fields as required.
  • :check - lambda or another object which respond to call. It rewrites of completeness check method. You can define a custom method. It should take two arguments (object and checked value) and return true or false. Default method is ->(obj, value){ value.present? }.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request