An open API service indexing awesome lists of open source software.

https://github.com/phstc/acts_as_working_days

acts_as_working_days is a Rails plugin to add working days on models
https://github.com/phstc/acts_as_working_days

Last synced: about 1 year ago
JSON representation

acts_as_working_days is a Rails plugin to add working days on models

Awesome Lists containing this project

README

          

= ActsAsWorkingDays

acts_as_working_days is a Rails plugin to add working days to your models

== Usage

=== Adding acts_as_working_days

# app/models/company.rb
class Company < ActiveRecord::Base
acts_as_working_days
end

=== Verifying a working day

kwik_e_mart = Company.new(:name => 'Kwik-E-Mart')

# Verifies if kwik_e_mart is opened now (Time.now)
kwik_e_mart.working_day?

# Verifies if kwik_e_mart is opened on Sundays
kwik_e_mart.working_day?(:week_day => 0)

# Verifies if kwik_e_mart is opened on Mondays 21h30
kwik_e_mart.working_day?(:week_day => 1, :hour => 21, :min => 30)

week_day is an integer representing the day of the week, 0..6, with Sunday == 0.
(See http://www.ruby-doc.org/core-2.1.1/Time.html#method-i-wday)

=== Setting working days

kwik_e_mart = Company.new(:name => 'Kwik-E-Mart')

# Set kwik_e_mart is opened on Mondays from 8h30 to 18h45
kwik_e_mart.working_days.build(:week_day => 1, :start_hour => 8, :start_min => 30, :end_hour => 18, :end_min => 45)

# Set kwik_e_mart is opened on Saturdays from 10h00 to 16h00
kwik_e_mart.working_days.build(:week_day => 6, :start_hour => 10, :start_min => 0, :end_hour => 16, :end_min => 0)

# retuns true
kwik_e_mart.working_day?(:week_day => 1)

# returns true
kwik_e_mart.working_day?(:week_day => 1, :hour => 18)

# return true
kwik_e_mart.working_day?(:week_day => 1, :hour => 12, :min => 30)

# return false
kwik_e_mart.working_day?(:week_day => 1, :hour => 21, :min => 30)

=== Creating html form to set the working days

# app/views/company/new.html.erb
<% form_for @company do |f| %>
<%= f.error_messages %>

Company fields



<%= f.label :name, 'Company name' %>

<%= f.text_field :name %>


Workings days





Day
Open
Close



<% f.fields_for :working_days, @address.working_days_defaults do | working_day_form | %>


<%= t "week_day.day_#{working_day_form.object.week_day}" %>

<%= working_day_form.hidden_field :week_day %>
<%= working_day_form.select :start_hour, 0..23, {}, {:class => 'select'} %>
<%= working_day_form.select :start_min, 0..59, {}, {:class => 'select'} %>


<%= working_day_form.select :end_hour, 0..23, {}, {:class => 'select'} %>
<%= working_day_form.select :end_min, 0..59, {}, {:class => 'select'} %>


<% end %>


<% end %>

=== Creating I18n file to translate numeric week day to string

#config/locales/en.yml
week_day:
day_0: Sunday
day_1: Monday
day_2: Tuesday
day_3: Wednesday
day_4: Thursday
day_5: Friday
day_6: Saturday

=== Setting rails application time zone

Don't forget to set the time zone in your Rails application enviroment

# config/enviroment.rb
Rails::Initializer.run do |config|
#...
config.time_zone = 'Brasilia'
#...
end

To list all supported time zones
$ rake time:zones:all

(See http://wiki.rubyonrails.org/howtos/time-zones)

== Installation

=== Rails 2.3.x

==== Plugin

script/plugin install git://github.com/phstc/acts_as_working_days

==== Gem

# config/environment.rb:
config.gem 'acts_as_working_days'

==== Post Installation

1. script/generate acts_as_working_days_migration
2. rake db:migrate

=== Rails 3.0

==== Plugin

script/plugin install git://github.com/phstc/acts_as_working_days

==== Post Installation

1. rails generate acts_as_working_days:migration
2. rake db:migrate

== Testing

rake test

Copyright (c) 2010 Pablo Cantero, released under the MIT license