iu-test-factory 0.5.4.2 → 0.7.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3ea4ae667f09f498f06cc42c864ce19f6b58889d06773003f6c7fff485df5c7
4
- data.tar.gz: 9b17a101a1912e39c194bb2b1f1308b1829ebf23353d4f717654bb1eeb4b496b
3
+ metadata.gz: '09d68db8e2596a6eac1cc2ae52a153a8edf09cd9850d275b7c9f86c6c2efbf5f'
4
+ data.tar.gz: 2aaa3ece4d66d12e87c609ad94a17d0f2782e35546880a10b91ba97b0ac88376
5
5
  SHA512:
6
- metadata.gz: b246c41552684f183328d2727480118eb01959ee62105e1ba2d6bdd1b2af0167edc0f5a880b10e7126458dc7930cee83cee0364a66a015f0bcddc1014abd2015
7
- data.tar.gz: '009c47f65b12af13855013d6db260c90bd5705947399028ca6aec55f3ac4cd3ac07f9b972a258dbd902663913ec41e18151936989682637e7fe89548de8b03a0'
6
+ metadata.gz: 2780590cea9a09a078d24081dd7fa04dfb4c1e2a16c3d0b91293c8594257b45c17176e1051bcf19e41eac3d8ddd34b182c905f6bcc107c06ea4bfb17bb41f4ea
7
+ data.tar.gz: f4d087e16ab556736f1012f9a6aaeb9c36fba9dbbab2b23302e98b0a2425e20e832774121250db1fc1bf9018203c143c4a940259c27d91f7d6c8af60d1100ab2
data/Gemfile CHANGED
@@ -1,5 +1,7 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
2
 
3
- gem 'watir', '>=6.0.0'
3
+ source 'http://rubygems.org'
4
+
5
+ gem 'watir', '~> 7.0'
4
6
 
5
7
  gemspec
data/Gemfile.lock CHANGED
@@ -1,28 +1,32 @@
1
- PATH
2
- remote: .
3
- specs:
4
- test-factory (0.5.4)
5
- watir (>= 6.0.0)
6
-
7
- GEM
8
- remote: http://rubygems.org/
9
- specs:
10
- childprocess (0.8.0)
11
- ffi (~> 1.0, >= 1.0.11)
12
- ffi (1.9.18)
13
- rubyzip (1.2.1)
14
- selenium-webdriver (3.7.0)
15
- childprocess (~> 0.5)
16
- rubyzip (~> 1.0)
17
- watir (6.9.0)
18
- selenium-webdriver (~> 3.4, >= 3.4.1)
19
-
20
- PLATFORMS
21
- ruby
22
-
23
- DEPENDENCIES
24
- test-factory!
25
- watir (>= 6.0.0)
26
-
27
- BUNDLED WITH
28
- 1.15.4
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ iu-test-factory (0.7.0.0)
5
+ watir (~> 7.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ childprocess (4.1.0)
11
+ regexp_parser (2.7.0)
12
+ rexml (3.2.5)
13
+ rubyzip (2.3.2)
14
+ selenium-webdriver (4.3.0)
15
+ childprocess (>= 0.5, < 5.0)
16
+ rexml (~> 3.2, >= 3.2.5)
17
+ rubyzip (>= 1.2.2, < 3.0)
18
+ websocket (~> 1.0)
19
+ watir (7.2.2)
20
+ regexp_parser (>= 1.2, < 3)
21
+ selenium-webdriver (~> 4.2)
22
+ websocket (1.2.9)
23
+
24
+ PLATFORMS
25
+ x64-mingw-ucrt
26
+
27
+ DEPENDENCIES
28
+ iu-test-factory!
29
+ watir (~> 7.0)
30
+
31
+ BUNDLED WITH
32
+ 2.3.22
data/LICENSE CHANGED
@@ -1,68 +1,13 @@
1
- Apache License, Version 2.0
2
- Apache License
3
- Version 2.0, January 2004
4
- http://www.apache.org/licenses/
1
+ Copyright (C) 2023 Indiana University
5
2
 
6
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
7
6
 
8
- 1. Definitions.
7
+ http://www.apache.org/licenses/LICENSE-2.0
9
8
 
10
- "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
13
-
14
- "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
15
-
16
- "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
17
-
18
- "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
19
-
20
- "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
21
-
22
- "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
23
-
24
- "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
25
-
26
- "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
27
-
28
- "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
29
-
30
- 2. Grant of Copyright License.
31
-
32
- Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
33
-
34
- 3. Grant of Patent License.
35
-
36
- Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
37
-
38
- 4. Redistribution.
39
-
40
- You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
41
-
42
- You must give any other recipients of the Work or Derivative Works a copy of this License; and
43
- You must cause any modified files to carry prominent notices stating that You changed the files; and
44
- You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
45
- If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
46
- You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
47
-
48
- 5. Submission of Contributions.
49
-
50
- Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
51
-
52
- 6. Trademarks.
53
-
54
- This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
55
-
56
- 7. Disclaimer of Warranty.
57
-
58
- Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
59
-
60
- 8. Limitation of Liability.
61
-
62
- In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
63
-
64
- 9. Accepting Warranty or Additional Liability.
65
-
66
- While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
67
-
68
- END OF TERMS AND CONDITIONS
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
Binary file
@@ -1,13 +1,15 @@
1
- spec = Gem::Specification.new do |s|
1
+ Gem::Specification.new do |s|
2
2
  s.name = 'iu-test-factory'
3
- s.version = '0.5.4.2'
4
- s.summary = %q{framework for creating automated testing scripts}
5
- s.description = %q{This gem provides a set of modules and methods to help quickly and DRYly create a test automation framework using Ruby and Watir.}
6
- s.files = Dir.glob("**/**/**")
7
- s.test_files = Dir.glob("test/*test_rb")
8
- s.authors = ['Abraham Heward']
9
- s.email = %w{aheward@rsmart.com}
3
+ s.version = '0.7.0.0'
4
+ s.summary = 'framework for creating automated testing scripts'
5
+ s.description = 'This gem provides a set of modules and methods to help quickly and DRYly create a test \
6
+ automation framework using Ruby and Watir.'
7
+ s.files = Dir.glob('**/**/**')
8
+ s.test_files = Dir.glob('test/*test_rb')
9
+ s.authors = ['Abraham Heward', 'David Elyea', 'Megha Ramawat']
10
+ s.email = ['aheward@rsmart.com', 'delyea@iu.edu', 'mramawat@iu.edu']
10
11
  s.homepage = 'https://github.iu.edu/iu-uits-es'
11
- s.add_dependency 'watir', '>= 6.0.0'
12
- s.required_ruby_version = '>= 2.0.0'
12
+ s.add_dependency 'watir', '~> 7.0'
13
+ s.required_ruby_version = '~> 3.1'
14
+ s.license = 'Apache-2.0'
13
15
  end
@@ -164,4 +164,4 @@ module StringFactory
164
164
  end
165
165
  module_function :damballa
166
166
 
167
- end
167
+ end
@@ -1,16 +1,19 @@
1
- module TestFactory
1
+ # frozen_string_literal: true
2
2
 
3
+ # Module to define full TestFactory binary tranform
4
+ module TestFactory
3
5
  def self.binary_transform(var)
4
- case(var)
5
- when nil
6
- nil
7
- when /yes/i, /on/i, :set, true
8
- :set
9
- when /no/i, /off/i, :clear, false
10
- :clear
11
- else
12
- raise "The value of your DataObject's checkbox/radio ('#{var}') instance variable is not supported.\nPlease make sure the value conforms to one of the following patterns:\n\n - :set or :clear (Symbol)\n - 'yes', 'no', 'on', or 'off' (String; case insensitive)\n - true or false (Boolean)"
6
+ case var
7
+ when nil
8
+ nil
9
+ when /yes/i, /on/i, :set, true
10
+ :set
11
+ when /no/i, /off/i, :clear, false
12
+ :clear
13
+ else
14
+ raise "The value of your DataObject's checkbox/radio ('#{var}') instance variable is not supported.\n /
15
+ Please make sure the value conforms to one of the following patterns:\n\n - :set or :clear (Symbol)\n /
16
+ - 'yes', 'no', 'on', or 'off' (String; case insensitive)\n - true or false (Boolean)"
13
17
  end
14
18
  end
15
-
16
- end
19
+ end
data/lib/test-factory.rb CHANGED
@@ -14,5 +14,5 @@
14
14
 
15
15
  require 'watir'
16
16
  require 'forwardable'
17
- %w{foundry.rb data_factory.rb}.each { |f| require "#{File.dirname(__FILE__)}/test-factory/#{f}" }
18
- Dir["#{File.dirname(__FILE__)}/test-factory/*.rb"].each {|f| require f }
17
+ %w[foundry.rb data_factory.rb].each { |f| require "#{File.dirname(__FILE__)}/test-factory/#{f}" }
18
+ Dir["#{File.dirname(__FILE__)}/test-factory/*.rb"].each { |f| require f }
metadata CHANGED
@@ -1,33 +1,38 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iu-test-factory
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4.2
4
+ version: 0.7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abraham Heward
8
+ - David Elyea
9
+ - Megha Ramawat
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2021-03-08 00:00:00.000000000 Z
13
+ date: 2023-03-28 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: watir
15
17
  requirement: !ruby/object:Gem::Requirement
16
18
  requirements:
17
- - - ">="
19
+ - - "~>"
18
20
  - !ruby/object:Gem::Version
19
- version: 6.0.0
21
+ version: '7.0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
- - - ">="
26
+ - - "~>"
25
27
  - !ruby/object:Gem::Version
26
- version: 6.0.0
27
- description: This gem provides a set of modules and methods to help quickly and DRYly
28
- create a test automation framework using Ruby and Watir.
28
+ version: '7.0'
29
+ description: |-
30
+ This gem provides a set of modules and methods to help quickly and DRYly create a test \
31
+ automation framework using Ruby and Watir.
29
32
  email:
30
33
  - aheward@rsmart.com
34
+ - delyea@iu.edu
35
+ - mramawat@iu.edu
31
36
  executables: []
32
37
  extensions: []
33
38
  extra_rdoc_files: []
@@ -37,19 +42,19 @@ files:
37
42
  - Gemfile.lock
38
43
  - LICENSE
39
44
  - README.md
45
+ - iu-test-factory-0.6.0.beta1.gem
40
46
  - iu-test-factory.gemspec
41
47
  - lib/test-factory.rb
42
48
  - lib/test-factory/collections_factory.rb
43
- - lib/test-factory/core_ext.rb
44
49
  - lib/test-factory/data_factory.rb
45
- - lib/test-factory/date_factory.rb
46
50
  - lib/test-factory/foundry.rb
47
51
  - lib/test-factory/gem_ext.rb
48
52
  - lib/test-factory/page_factory.rb
49
53
  - lib/test-factory/string_factory.rb
50
54
  - lib/test-factory/test_factory.rb
51
55
  homepage: https://github.iu.edu/iu-uits-es
52
- licenses: []
56
+ licenses:
57
+ - Apache-2.0
53
58
  metadata: {}
54
59
  post_install_message:
55
60
  rdoc_options: []
@@ -57,16 +62,16 @@ require_paths:
57
62
  - lib
58
63
  required_ruby_version: !ruby/object:Gem::Requirement
59
64
  requirements:
60
- - - ">="
65
+ - - "~>"
61
66
  - !ruby/object:Gem::Version
62
- version: 2.0.0
67
+ version: '3.1'
63
68
  required_rubygems_version: !ruby/object:Gem::Requirement
64
69
  requirements:
65
70
  - - ">="
66
71
  - !ruby/object:Gem::Version
67
72
  version: '0'
68
73
  requirements: []
69
- rubygems_version: 3.0.3
74
+ rubygems_version: 3.3.7
70
75
  signing_key:
71
76
  specification_version: 4
72
77
  summary: framework for creating automated testing scripts
@@ -1,133 +0,0 @@
1
- # Copyright 2012-2014 The rSmart Group, Inc.
2
-
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
-
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- class Time
16
-
17
- # Using the :year_range option (or no option), this method creates a
18
- # Time object of a random value, within
19
- # the year range specified (default is 5 years in the past).
20
- #
21
- # Using the :series option, this method returns an array
22
- # containing a randomized Time object as its first element (limited by
23
- # the specified :year_range value). Subsequent elements will be Time objects
24
- # with values putting them later than the prior element, within the specified
25
- # range value (see examples).
26
- #
27
- # Usage Examples:
28
- # @example
29
- # a random date...
30
- # ?> Time.random
31
- # => Tue Aug 05 00:00:00 EDT 2007
32
- #
33
- # birthdays, anyone?...
34
- # 5.times { p Time.random(:year_range=>80) }
35
- # Wed Feb 06 00:00:00 EDT 1974
36
- # Tue Dec 22 00:00:00 EST 1992
37
- # Fri Apr 14 00:00:00 EWT 1944
38
- # Thu Jul 01 00:00:00 EDT 1993
39
- # Wed Oct 02 00:00:00 EDT 2002
40
- #
41
- # A series of dates are useful for account-related info...
42
- # ?> Time.random(:series=>[20.days, 3.years])
43
- # => [Sat Jan 22 00:00:00 EST 2005,
44
- # Sat Jan 29 12:58:45 EST 2005,
45
- # Fri Sep 08 09:34:58 EDT 2006]
46
- #
47
- # or maybe to simulate events during an hour?...
48
- # ?> Time.random(:series=>[1.hour,1.hour,1.hour])
49
- # => [Wed Apr 21 00:00:00 EDT 2004,
50
- # Wed Apr 21 00:45:59 EDT 2004,
51
- # Wed Apr 21 01:02:47 EDT 2004,
52
- # Wed Apr 21 01:31:00 EDT 2004]
53
- #
54
- def self.random(params={})
55
- years_back = params[:year_range] || 5
56
- year = (rand * (years_back)).ceil + (Time.now.year - years_back)
57
- month = (rand * 12).ceil
58
- day = (rand * 31).ceil
59
- series = [date = Time.local(year, month, day)]
60
- if params[:series]
61
- params[:series].each do |some_time_after|
62
- series << series.last + (rand * some_time_after).ceil
63
- end
64
- return series
65
- end
66
- date
67
- end
68
-
69
- end # Time
70
-
71
- module Enumerable
72
-
73
- # Use for getting a natural sort order instead of the ASCII
74
- # sort order.
75
- #
76
- def alphabetize
77
- sort { |a, b| grouped_compare(a, b) }
78
- end
79
-
80
- # Use for sorting an Enumerable object in place.
81
- #
82
- def alphabetize!
83
- sort! { |a, b| grouped_compare(a, b) }
84
- end
85
-
86
- private
87
-
88
- def grouped_compare(a, b)
89
- loop {
90
- a_chunk, a = extract_alpha_or_number_group(a)
91
- b_chunk, b = extract_alpha_or_number_group(b)
92
- ret = a_chunk <=> b_chunk
93
- return -1 if a_chunk == ''
94
- return ret if ret != 0
95
- }
96
- end
97
-
98
- def extract_alpha_or_number_group(item)
99
- test_item = item.downcase
100
- matchdata = /([a-z]+|[\d]+)/.match(test_item)
101
- if matchdata.nil?
102
- ["", ""]
103
- else
104
- [matchdata[0], test_item = test_item[matchdata.offset(0)[1] .. -1]]
105
- end
106
- end
107
-
108
- end # Enumerable
109
-
110
- class Numeric
111
-
112
- # Converts a number object to a string containing commas every 3rd digit. Adds
113
- # trailing zeroes if necessary to match round currency amounts.
114
- def commas
115
- self.to_s =~ /([^\.]*)(\..*)?/
116
- int, dec = $1.reverse, $2 ? ('%.2f' % $2).to_s[/.\d+$/] : ".00"
117
- while int.gsub!(/(,|\.|^)(\d{3})(\d)/, '\1\2,\3')
118
- end
119
- int.reverse + dec
120
- end
121
-
122
- end # Numeric
123
-
124
- class String
125
-
126
- # Used to remove commas and dollar signs from long number strings,
127
- # then converting the result to a Float so that it
128
- # can be used in calculations.
129
- def groom
130
- self.gsub(/[$,]/,'').to_f
131
- end
132
-
133
- end # String
@@ -1,158 +0,0 @@
1
- # Copyright 2012-2014 The rSmart Group, Inc.
2
-
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
-
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- # Some date and time helper functions....
16
- module DateFactory
17
-
18
- MONTHS = %w{JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC}
19
-
20
- # Takes a time object and returns a hash containing
21
- # various parts of the relevant date.
22
- # @param time_object [Time] the moment you want to convert
23
- # @returns [Hash] a hash object containing various parts of the date/time you passed to the method
24
- #
25
- def date_factory(time_object)
26
- {
27
- sakai: make_date(time_object),
28
- sakai_rounded: make_date(time_object).gsub!(/:\d+/, ":#{Time.at(time_object.to_i/(5*60)*(5*60)).strftime("%M")}"), # Date with time rounded to nearest 5-minute mark.
29
- short_date: time_object.strftime("%b %-d, %Y"), # => "Oct 18, 2013"
30
- samigo: time_object.strftime("%m/%d/%Y %I:%M:%S %p"), # => "10/30/2012 07:02:05 AM"
31
- MON: time_object.strftime("%^b"), # => "DEC"
32
- Mon: time_object.strftime("%b"), # => "Jan"
33
- Month: time_object.strftime("%B"), # => "February"
34
- month_int: time_object.month, # => 3
35
- day_of_month: time_object.day, # => 17 Note this is not zero-padded
36
- weekday: time_object.strftime("%A"), # => "Monday"
37
- wkdy: time_object.strftime("%a"), # => "Tue"
38
- year: time_object.year, # => 2013
39
- hour: time_object.strftime("%I").to_i, # => "07" Zero-padded, 12-hour clock
40
- minute: time_object.strftime("%M"), # => "02" Zero-padded
41
- minute_rounded: (Time.at(time_object.to_i/(5*60)*(5*60))).strftime("%M"), # => "05" Zero-padded, rounded to 5-minute increments
42
- meridian: time_object.strftime("%P"), # => "pm"
43
- MERIDIAN: time_object.strftime("%p"), # => "AM"
44
- date_w_slashes: time_object.strftime("%m/%d/%Y"), # => 02/08/2013
45
- custom: time_object # => Allows creation of a custom date string using the passed time value.
46
- }
47
- end
48
-
49
- def an_hour_ago
50
- date_factory(Time.now - 3600)
51
- end
52
- alias last_hour an_hour_ago
53
-
54
- def right_now
55
- date_factory(Time.now)
56
- end
57
-
58
- def in_an_hour
59
- date_factory(Time.now + 3600)
60
- end
61
- alias next_hour in_an_hour
62
-
63
- def last_year
64
- date_factory(Time.now - (3600*24*365))
65
- end
66
- alias a_year_ago last_year
67
-
68
- # Returns a randomly selected date/time from
69
- # within the last year.
70
- def in_the_last_year
71
- date_factory(Time.random(:year_range=>1))
72
- end
73
-
74
- def last_month
75
- index = MONTHS.index(current_month)
76
- return MONTHS[index-1]
77
- end
78
-
79
- def hours_ago(hours)
80
- date_factory(Time.now - hours*3600)
81
- end
82
-
83
- def hours_from_now(hours)
84
- date_factory(Time.now + hours*3600)
85
- end
86
-
87
- # Takes an integer representing
88
- # the count of minutes as the parameter, and
89
- # returns the date_factory hash for the
90
- # resulting Time value.
91
- #
92
- def minutes_ago(mins)
93
- date_factory(Time.now - mins*60)
94
- end
95
-
96
- def minutes_from_now(mins)
97
- date_factory(Time.now + mins*60)
98
- end
99
-
100
- # Returns the current month as an
101
- # upper-case 3-letter string.
102
- # example: "JUL"
103
- #
104
- def current_month
105
- Time.now.strftime("%^b")
106
- end
107
-
108
- def next_month
109
- index = MONTHS.index(current_month)
110
- if index < 11
111
- return MONTHS[index+1]
112
- else
113
- return MONTHS[0]
114
- end
115
- end
116
-
117
- def in_a_year
118
- date_factory(Time.now + (3600*24*365))
119
- end
120
- alias next_year in_a_year
121
-
122
- def yesterday
123
- date_factory(Time.now - (3600*24))
124
- end
125
-
126
- def tomorrow
127
- date_factory(Time.now + (3600*24))
128
- end
129
-
130
- def in_a_week
131
- date_factory(Time.now + (3600*24*7))
132
- end
133
- alias next_week in_a_week
134
-
135
- def a_week_ago
136
- date_factory(Time.now - (3600*24*7))
137
- end
138
-
139
- def next_monday
140
- date_factory(Time.at(Time.now+(8-Time.now.wday)*24*3600))
141
- end
142
-
143
- # Formats a date string Sakai-style.
144
- # Useful for verifying creation dates and such.
145
- #
146
- # @param time_object [Time] the moment that you want converted to the string
147
- # @returns [String] a date formatted to look like this: Jun 8, 2012 12:02 pm
148
- #
149
- def make_date(time_object)
150
- month = time_object.strftime("%b ")
151
- day = time_object.strftime("%-d")
152
- year = time_object.strftime(", %Y ")
153
- mins = time_object.strftime(":%M %P")
154
- hour = time_object.strftime("%l").to_i
155
- return month + day + year + hour.to_s + mins
156
- end
157
-
158
- end