calendar_formatter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4574b5dff81a2f2344c3e6daa00136eb8fea7762
4
+ data.tar.gz: 372fc402cc2b900d85a1a41f30e94be0bd9482dc
5
+ SHA512:
6
+ metadata.gz: 8c765b7472bc75f663a879ec5b8b0b5bb431201fdcd2818320112bb02e736ebe1996061b9d7101dfb72292e04bb07830d384bfb6d31b4e28ecf6ff933c5b388d
7
+ data.tar.gz: 68c0b22a797d6e6fd0066ed3ed75103f83b72bae8669decd23f7cecd0bbdede52e6a32c36dc1bc123e4f5cca0667c250a094f6dee842074684eb6dc0ffd48a6d
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /gemfiles/*.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ gemfile:
7
+ - gemfiles/activesupport-4.0.gemfile
8
+ - gemfiles/activesupport-4.1.gemfile
9
+ - gemfiles/activesupport-4.2.gemfile
10
+ - Gemfile
11
+ before_install: gem install bundler
12
+ script: bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in calendar_formatter.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Pavel Makarov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # CalendarFormatter
2
+
3
+ [![Build Status](https://travis-ci.org/violarium/calendar_formatter.svg?branch=master)](https://travis-ci.org/violarium/calendar_formatter)
4
+
5
+ Simple gem to format weeks and months days.
6
+
7
+ It allows you to select start week day and get dates ranges according to it for week or month.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'calendar_formatter'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install calendar_formatter
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require 'calendar_formatter'
29
+ fomratter = CalendarFormatter::Formatter.new(start_wday: :sunday)
30
+ fomratter.week(Date.today) # get range of dates for this week
31
+ fomratter.month(Date.today) # get range of dates for this month
32
+ fomratter.month(Date.today, padding: true) # get range of dates for this month but with padding - 6 weeks to get all the months same size
33
+ ```
34
+
35
+
36
+ ## Development
37
+
38
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
39
+
40
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
41
+
42
+ ## Contributing
43
+
44
+ Bug reports and pull requests are welcome on GitHub at https://github.com/violarium/calendar_formatter.
45
+
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'calendar_formatter'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'calendar_formatter/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'calendar_formatter'
8
+ spec.version = CalendarFormatter::VERSION
9
+ spec.authors = ['Pavel Makarov']
10
+ spec.email = ['metus.violarium@gmail.com']
11
+
12
+ spec.summary = %q{Simple gem to format weeks and months days.}
13
+ spec.description = %q{Gem which allows you to select start week day and get dates ranges according to it.}
14
+ spec.homepage = 'https://github.com/violarium/calendar_formatter'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+ spec.add_runtime_dependency 'activesupport'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ end
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in calendar_formatter.gemspec
4
+ gemspec path: '..'
5
+
6
+ gem 'activesupport', '~> 4.1'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in calendar_formatter.gemspec
4
+ gemspec path: '..'
5
+
6
+ gem 'activesupport', '~> 4.0'
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in calendar_formatter.gemspec
4
+ gemspec path: '..'
5
+
6
+ gem 'activesupport', '~> 4.0'
@@ -0,0 +1,6 @@
1
+ require 'calendar_formatter/version'
2
+ require 'calendar_formatter/formatter'
3
+
4
+ module CalendarFormatter
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,58 @@
1
+ require 'active_support/core_ext/date'
2
+ require 'active_support/core_ext/time'
3
+ require 'active_support/core_ext/numeric/time'
4
+
5
+ module CalendarFormatter
6
+ class Formatter
7
+ # 42 - 6 weeks - max amount of weeks in month. Needs for padding.
8
+ DAYS_PER_MONTH = 42
9
+
10
+
11
+ # Create formatter.
12
+ #
13
+ # @param start_wday [Symbol] available values from :monday to :sunday
14
+ #
15
+ # @return self
16
+ def initialize(start_wday: :monday)
17
+ unless ::DateAndTime::Calculations::DAYS_INTO_WEEK.has_key?(start_wday)
18
+ raise ArgumentError, 'Argument start_wday is not correct'
19
+ end
20
+ @start_wday = start_wday
21
+ end
22
+
23
+
24
+ # Get range of formatted dates for week.
25
+ #
26
+ # @param date [Date]
27
+ #
28
+ # @return [Range<Date>]
29
+ def week(date)
30
+ first_week_day = date.beginning_of_week(@start_wday)
31
+ last_week_day = date.end_of_week(@start_wday)
32
+ first_week_day .. last_week_day
33
+ end
34
+
35
+
36
+ # Get range of formatted dates for month.
37
+ #
38
+ # @param date [Date]
39
+ # @param padding [Boolean]
40
+ #
41
+ # @return [Range<Date>]
42
+ def month(date, padding: false)
43
+ first_month_day = date.beginning_of_month
44
+ last_month_day = first_month_day.end_of_month
45
+
46
+ first_week_day = first_month_day.beginning_of_week(@start_wday)
47
+ last_week_day = last_month_day.end_of_week(@start_wday)
48
+
49
+ if padding
50
+ while (last_week_day - first_week_day).to_i + 1 < DAYS_PER_MONTH
51
+ last_week_day = last_week_day + 1.week
52
+ end
53
+ end
54
+
55
+ first_week_day .. last_week_day
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module CalendarFormatter
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: calendar_formatter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Makarov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Gem which allows you to select start week day and get dates ranges according
70
+ to it.
71
+ email:
72
+ - metus.violarium@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - calendar_formatter.gemspec
87
+ - gemfiles/activesupport-4.0.gemfile
88
+ - gemfiles/activesupport-4.1.gemfile
89
+ - gemfiles/activesupport-4.2.gemfile
90
+ - lib/calendar_formatter.rb
91
+ - lib/calendar_formatter/formatter.rb
92
+ - lib/calendar_formatter/version.rb
93
+ homepage: https://github.com/violarium/calendar_formatter
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.8
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Simple gem to format weeks and months days.
117
+ test_files: []