Socket
Book a DemoInstallSign in
Socket

spok

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

spok

2.1.8
bundlerRubygems
Version published
Maintainers
1
Created
Source

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

NOTE: All methods available on Spok::Workday now are available on Spok interface, Spok::Workday still works but we have plans to make Spok:: Workday a private resource, you should update your code to rely on Spok interface.

You can use the Spok to check if a date is either a rest day or a workday:

require 'spok'

Spok.restday?(Date.new(2012, 12, 24))
# => false

Spok.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?(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

Adding custom calendars

If you need to add your own restday calendar, call Spok.add_calendar on your application boot:

Spok.add_calendar(:custom_calendar, './config/calendars/custom.yml')

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).

FAQs

Package last updated on 02 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.