i18n-beginning_of_week 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: f45d272464d1dab2a4048b92b0dd65b02117b5d4
4
+ data.tar.gz: 19fc02014735aaecafab4b14f2f89106d514e9b9
5
+ SHA512:
6
+ metadata.gz: eeee7d51d1949a6e56815362f10bffd3c7b4f6eb8e95e2dc5287893e94d683c1bc4c5d34a41b6e3dd1a5b713c1faf417ff2628f1bf8400da30eac1a2cd700986
7
+ data.tar.gz: 34ee76f2ad62bb2ceab7e3fcb566149f051626522fb603cd219f3a57d29a31d90756cdea48a952bd34886ced5d81746f3de1bb87bd131826b654e5da1700d8b8
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in i18n-beginning_of_week.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Mark Edmondson
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,83 @@
1
+ # I18n::BeginningOfWeek
2
+
3
+ Different places use different days of the week for the beginning of the week. Ruby allows a configuration variable to be set that
4
+ will change it but that assumes all users have the same beginning of the week requirement. This gem uses I18n to determine the beginning of the week value based on locale allowing users to have automatic different beginning of week settings.
5
+
6
+ The locale days of week are taken from [momentjs](https://github.com/moment/moment). Changes and corrections are welcome through pull requests.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'i18n-beginning_of_week'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install i18n-beginning_of_week
23
+
24
+ ## Usage
25
+
26
+ ### Get the beginning_of_week for a locale
27
+
28
+ ```
29
+ I18n.locale = :en
30
+ I18n.beginning_of_week # => :sunday
31
+ ```
32
+
33
+ OR
34
+
35
+ ```
36
+ I18n.beginning_of_week(:en) # => :sunday
37
+ ```
38
+
39
+ ### Set the Ruby configuration variable using the I18n.locale value or passed locale value
40
+
41
+ ```
42
+ I18n.locale = :fr
43
+ Date.beginning_of_week = I18n.beginning_of_week
44
+ Date.beginning_of_week # => :sunday
45
+ ```
46
+
47
+ OR
48
+
49
+ ```
50
+ Date.beginning_of_week = I18n.beginning_of_week(:fr)
51
+ Date.beginning_of_week # => :monday
52
+ ```
53
+
54
+
55
+ ### Run a block with the beginning of week value set using the I18n.locale value or passed locale value
56
+ ```
57
+ I18n.locale = :ar
58
+ I18n.in_beginning_of_week do
59
+ Date.beginning_of_week
60
+ end # => :saturday
61
+ ```
62
+
63
+ OR
64
+
65
+ ```
66
+ I18n.in_beginning_of_week(:ar) do
67
+ Date.beginning_of_week
68
+ end # => :saturday
69
+ ```
70
+
71
+ ## Development
72
+
73
+ 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.
74
+
75
+ 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).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://github.com/markedmondson/i18n-beginning_of_week.
80
+
81
+ ## License
82
+
83
+ 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,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "i18n/beginning_of_week"
5
+
6
+ require "irb"
7
+ IRB.start(__FILE__)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'i18n/beginning_of_week/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "i18n-beginning_of_week"
8
+ spec.version = I18n::BeginningOfWeek::VERSION
9
+ spec.authors = ["Mark Edmondson"]
10
+ spec.email = ["mark@retailzipline.com"]
11
+
12
+ spec.summary = %q{Get the beginning of the week from the current I18n locale.}
13
+ spec.description = %q{Different locales use different days for the beginning of the week. This gem allows the I18n locale to determine the beginning of the week day.}
14
+ spec.homepage = "https://github.com/markedmondson/i18n-beginning_of_week"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_dependency "i18n"
25
+ spec.add_dependency "activesupport"
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.14"
28
+ spec.add_development_dependency "pry", "~> 0.10.4"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
@@ -0,0 +1,64 @@
1
+ require "i18n/beginning_of_week/version"
2
+ require "i18n"
3
+ require "date"
4
+ require "active_support/core_ext/date/calculations"
5
+
6
+ module I18n
7
+ module Locale
8
+ module BeginningOfWeek
9
+ LOCALE_DAYS = {
10
+ 'af': :monday, 'ar-LY': :saturday, 'ar-MA': :saturday, 'ar-SA': :saturday, 'ar-TN': :monday, 'ar': :saturday,
11
+ 'az': :monday, 'bg': :monday, 'bn': :sunday, 'bo': :sunday, 'br': :monday, 'bs': :monday, 'ca': :monday,
12
+ 'cs': :monday, 'cv': :monday, 'cy': :monday, 'da': :monday, 'de-at': :monday, 'de': :monday, 'dv': :sunday,
13
+ 'el': :monday, 'en-au': :monday, 'en-ca': :monday, 'en-db': :monday, 'en-ie': :monday, 'en-nz': :monday,
14
+ 'en': :sunday, 'eo': :monday, 'es-do': :monday, 'es': :monday, 'et': :monday, 'eu': :monday, 'fa': :saturday,
15
+ 'fi': :monday, 'fo': :monday, 'fr-ca': :monday, 'fr-ch': :monday, 'fr': :monday, 'fy': :monday, 'gd': :monday,
16
+ 'gl': :monday, 'gom-latn': :monday, 'he': :sunday, 'hi': :sunday, 'hr': :monday, 'hu': :monday, 'hy-am': :monday,
17
+ 'id': :monday, 'is': :monday, 'it': :monday, 'ja': :monday, 'jv': :monday, 'ka': :monday, 'kk': :monday, 'km': :monday,
18
+ 'kn': :sunday, 'ko': :sunday, 'ky': :monday, 'lb': :monday, 'lo': :sunday, 'lt': :monday, 'lv': :monday, 'me': :monday,
19
+ 'mi': :monday, 'mk': :monday, 'mr': :sunday, 'ms-my': :monday, 'ms': :monday, 'my': :monday, 'nb': :monday,
20
+ 'ne': :sunday, 'nl-be': :monday, 'nl': :monday, 'nn': :monday, 'pa-in': :sunday, 'pl': :monday, 'pt-rb': :sunday,
21
+ 'pt': :monday, 'ro': :monday, 'ru': :monday, 'sd': :monday, 'se': :monday,'si': :sunday, 'sk': :monday, 'sl': :monday,
22
+ 'sq': :monday, 'sr-cryl': :monday, 'sr': :monday, 'ss': :monday, 'sv': :monday, 'sw': :monday, 'ta': :sunday,
23
+ 'te': :sunday, 'tet': :monday, 'th': :sunday, 'tl-ph': :monday, 'tlh': :monday, 'tr': :monday, 'tzl': :monday,
24
+ 'tzl-latn': :saturday, 'tzm': :saturday, 'uk': :monday, 'ur': :monday, 'uz-latn': :monday, 'uz': :monday,
25
+ 'vi': :monday, 'yo': :monday, 'zh-cn': :monday, 'zh-hk': :monday, 'zh-tq': :monday
26
+ }.freeze
27
+
28
+ def self.included(base)
29
+ base.extend ClassMethods
30
+ end
31
+
32
+ module ClassMethods
33
+ # Get the beginning of week symbol based on the locale
34
+ # @return [Symbol]
35
+ def beginning_of_week(locale = I18n.locale)
36
+ LOCALE_DAYS[locale] || Date.beginning_of_week
37
+ end
38
+
39
+ # Run the block in the context of the i18n beginning of the week
40
+ # @param [Block]
41
+ def in_beginning_of_week(locale = I18n.locale)
42
+ original_beginning_of_week = Date.beginning_of_week
43
+ Date.beginning_of_week = beginning_of_week(locale)
44
+ yield
45
+ ensure
46
+ Date.beginning_of_week = original_beginning_of_week
47
+ end
48
+
49
+ private
50
+
51
+ # Gives us {0=>:sunday, 1=>:monday, 2=>:tuesday, 3=>:wednesday, 4=>:thursday, 5=>:friday, 6=>:saturday}
52
+ # Which is way more useful than Date::DAYS_INTO_WEEK :/
53
+ # @return [Hash<Integer,Symbol>]
54
+ def day_names_to_hash
55
+ Date::DAYNAMES.each_with_object(Hash.new).with_index do |(day, memo), index|
56
+ memo[index] = day.downcase.to_sym
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ I18n.include I18n::Locale::BeginningOfWeek
@@ -0,0 +1,5 @@
1
+ module I18n
2
+ module BeginningOfWeek
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n-beginning_of_week
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Mark Edmondson
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
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: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.14'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.14'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.4
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.4
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.0'
97
+ description: Different locales use different days for the beginning of the week. This
98
+ gem allows the I18n locale to determine the beginning of the week day.
99
+ email:
100
+ - mark@retailzipline.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rspec"
107
+ - ".travis.yml"
108
+ - Gemfile
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - i18n-beginning_of_week.gemspec
115
+ - lib/i18n/beginning_of_week.rb
116
+ - lib/i18n/beginning_of_week/version.rb
117
+ homepage: https://github.com/markedmondson/i18n-beginning_of_week
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.6.10
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Get the beginning of the week from the current I18n locale.
141
+ test_files: []