Coder Social home page Coder Social logo

spok's Introduction

Spok

By Magnetis

Build Status

Spok is a tool for dealing with workdays and restdays in an easy way. It also provides functionalities for working with periods of dates.

Installation

Add this line to your application's Gemfile:

gem 'spok'

And then execute:

$ bundle

Or install it yourself as:

$ gem install spok

Usage

Dealing with workdays

You can use the Spok::Workday module to check if a date is either a restday or a workday:

require 'spok'

Spok::Workday.workday?(Date.new(2012, 12, 24))
# => true

Spok also supports different calendars for checking if a date is a workday or a restday

require 'spok'

Spok::Workday.workday?(Date.new(2012, 12, 24), calendar: :bovespa)
# => false

If calendar is not informed, it will default to the :brazil calendar.

The available calendars are defined with .yml files here.

Working with periods of dates

Objects from the Spok class can be used to work with periods of dates. You can initialize a new object passing the start and end date for your period to the new method:

require 'spok'

period = Spok.new(Date.new(2018, 9, 14), Date.new(2018, 10, 14))
another_period = Spok.new(Date.today, Date.today + 10.days)

You can also use the Spok.parse method to initialize a new object using a string:

require 'spok'

parsed_period = Spok.parse('20180901-20180903')

With the object, you can check for all the workdays in that period of dates:

require 'spok'

period = Spok.new(Date.new(2018, 10, 10), Date.new(2018, 10, 14))
period.workdays
# => [Wed, 10 Oct 2018, Thu, 11 Oct 2018]

Set default calendar

Spok.default_calendar = :bovespa

Documentation

The complete documentation in the RDoc format is available here:

https://www.rubydoc.info/gems/spok

Contributing

Please read our Contributing guide for more information.

License

This project is licensed under the terms of the Apache 2. Copyright 2014-2018 Magnetis http://www.magnetis.com.br See the LICENSE file for license rights and limitations (Apache 2).

spok's People

Contributors

bezelga avatar hensou avatar hungdiep97 avatar igormarques avatar janukan avatar juancrg90 avatar lsunsi avatar lucianot avatar luizamagalhaes avatar luizrogeriocn avatar mkhira2 avatar noloman avatar philss avatar pille1842 avatar renatofmachado avatar ruan-brandao avatar scnfilho avatar stefannibrasil avatar thalesmello avatar veith3n avatar zainalmustofa avatar zvlex avatar

Watchers

 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.