datetimecomponent 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8fbdcce9b7b6a91b8ecdb0aced3287fc39984ba8813c8425714357cd9e40eb1b
4
+ data.tar.gz: 46dce78fc719870d4fa554e3f6c13f5bda036ad0f84c820648a27c87cf9b2591
5
+ SHA512:
6
+ metadata.gz: 108b1088b44a1198899d01d961d118fe4b0b3b06b53fa3bb35717d96822efbfc177896b3f009563357ac026ee70d83aedfcd2503a0c9617b9d8ab52a95e7ed89
7
+ data.tar.gz: 4817c7537f6e965d4791f378bb7afab1aeee500e0284a104a3227f4ac560e6358b9fd4ff6c702ee28f0415f8e108b8016ea4e4523798bc91796440ef6d90079e
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.4
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in datetimecomponent.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.7"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 squarebat
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.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Datetimecomponent
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/datetimecomponent`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'datetimecomponent'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install datetimecomponent
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ 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.
30
+
31
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/datetimecomponent.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "datetimecomponent"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/datetimecomponent/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "datetimecomponent"
7
+ spec.version = Datetime::VERSION
8
+ spec.authors = ["Khadija Sidhpuri"]
9
+ spec.email = ["ksidhpuri@gmail.com"]
10
+
11
+ spec.summary = "a view component to render datetime in several formats"
12
+ spec.description = "Rendering datetime in different formats and timezones just got easy"
13
+ spec.homepage = "https://rubygems.org/gems/datetimecomponent"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.4.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
19
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "rspec", "~> 3.2"
31
+ spec.add_dependency 'view_component', '~> 2.34'
32
+ spec.add_runtime_dependency "actionview", ">= 5.0.0"
33
+ spec.add_runtime_dependency "activesupport", ">= 5.0.0"
34
+ # For more information and examples about making a new gem, checkout our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Datetime
4
+ VERSION = "0.2.0"
5
+ end
@@ -0,0 +1,78 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "datetimecomponent/version"
4
+ require 'view_component/engine'
5
+
6
+ module Datetime
7
+ class Error < StandardError; end
8
+ class DatetimeComponent < ViewComponent::Base
9
+ FULL_DATETIME_ARGS = { null: '', short: '%a, %-d %b %y, %H:%M %Z', long: '%A, %-d %B %Y, %-l:%M %P %Z' }.freeze
10
+ DAY_ARGS = { null: '', numeric: '%-d' }.freeze
11
+ WEEKDAY_ARGS = { null: '', short: '%a', long: '%A'}.freeze
12
+ MONTH_ARGS = { null: '', short: '%b', long: '%B', numeric: '%-m' }.freeze
13
+ YEAR_ARGS = { null: '', short: '%-y', long: '%-Y' }.freeze
14
+ DISPLAY_TIME_ARGS = { null: '', h12: '%-l:%M', h12meridian: '%-l:%M %P', h24: '%H:%M' }.freeze
15
+
16
+ def initialize(custom_datetime_format: '', full_datetime: :null, date_separator: '/', weekday: :null,
17
+ day: :null, month: :null, year: :null, display_time: :null, display_timezone: false,
18
+ display_zone_offset: false, time_zone: 'UTC')
19
+ super
20
+ @date_separator = date_separator
21
+ @time_zone = TZInfo::Timezone.get(time_zone)
22
+ @datetime_format = custom_datetime_format
23
+ return unless @datetime_format.empty?
24
+
25
+ @format_args = {}
26
+ @format_args[:full_datetime] = FULL_DATETIME_ARGS[full_datetime]
27
+ @format_args[:weekday] = WEEKDAY_ARGS[weekday]
28
+ @format_args[:day] = DAY_ARGS[day]
29
+ @format_args[:month] = MONTH_ARGS[month]
30
+ @format_args[:year] = YEAR_ARGS[year]
31
+ @format_args[:display_time] = DISPLAY_TIME_ARGS[display_time]
32
+ @format_args[:display_timezone] = display_timezone ? '%Z' : ''
33
+ @format_args[:zone_offset] = display_zone_offset ? 'UTC %:z' : ''
34
+ @datetime_format = build_datetime_format
35
+ end
36
+
37
+ private
38
+
39
+ # rubocop:enable Metrics/ParameterLists
40
+ def build_datetime_format
41
+ datetime_format = @format_args[:full_datetime]
42
+ return "#{datetime_format} #{@format_args[:zone_offset]}" unless datetime_format.empty?
43
+
44
+ datetime_format += @format_args[:weekday]
45
+ datetime_format += ', ' if !datetime_format.empty? && !@format_args[:day].empty?
46
+
47
+ datetime_format += build_dateformat
48
+ datetime_format += ', ' if !datetime_format.empty? && !@format_args[:display_time].empty?
49
+
50
+ datetime_format += build_timeformat
51
+ datetime_format
52
+ end
53
+
54
+ def build_dateformat
55
+ date_format = @format_args[:day]
56
+
57
+ unless @format_args[:month].empty?
58
+ date_format += @format_args[:month] == MONTH_ARGS[:numeric] ? @date_separator : ' '
59
+ date_format += @format_args[:month]
60
+ end
61
+
62
+ unless @format_args[:year].empty?
63
+ date_format += @format_args[:month] == MONTH_ARGS[:numeric] ? @date_separator : ' '
64
+ date_format += @format_args[:year]
65
+ end
66
+ date_format
67
+ end
68
+
69
+ def build_timeformat
70
+ time_format = @format_args[:display_time]
71
+ time_format += ' ' unless @format_args[:display_time].empty?
72
+ time_format += @format_args[:display_timezone]
73
+ time_format += ' ' unless @format_args[:display_timezone].empty?
74
+ time_format += @format_args[:zone_offset]
75
+ time_format
76
+ end
77
+ end
78
+ end
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: datetimecomponent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Khadija Sidhpuri
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-08-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: view_component
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.34'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.34'
41
+ - !ruby/object:Gem::Dependency
42
+ name: actionview
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 5.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 5.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 5.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 5.0.0
69
+ description: Rendering datetime in different formats and timezones just got easy
70
+ email:
71
+ - ksidhpuri@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".rubocop.yml"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - datetimecomponent.gemspec
86
+ - lib/datetimecomponent.rb
87
+ - lib/datetimecomponent/version.rb
88
+ homepage: https://rubygems.org/gems/datetimecomponent
89
+ licenses:
90
+ - MIT
91
+ metadata:
92
+ homepage_uri: https://rubygems.org/gems/datetimecomponent
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: 2.4.0
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubygems_version: 3.2.22
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: a view component to render datetime in several formats
112
+ test_files: []