fora 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 493f33fe43f47d57b0e24a88737a9aa61ff9da23
4
+ data.tar.gz: c5e5018a46e934e3839bc97f03e39aae21cba3f7
5
+ SHA512:
6
+ metadata.gz: 4fbf568bff5831cbd3ae501bff4fa232032c5f7d7fe7dc34d0255213eecf082c144d9a190b0a5cc326975066ff8e99b479a6d90e9925e1e4d2d2de278d147140
7
+ data.tar.gz: e3b24369400e9bf92d2d06e85adfee6311bda0438e1d933df17d032e3341421634d1ccc8408e3355a51fa7db5a43afbaf7f37701f12379068836cc80a3cd23d9
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in fora.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 David Southard
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,58 @@
1
+ # Fora
2
+
3
+ *Why "fora"?* Its kind of the phoenetic pronunciation of the ancient greek
4
+ word for time, [φορά](https://en.wiktionary.org/wiki/%CF%86%CE%BF%CF%81%CE%AC)
5
+
6
+ *Uses?* simple transform of Time/Dates <-> String
7
+
8
+ **Dependencies**:
9
+ - ruby > 2.1
10
+ - contracts gem > 0.12.0
11
+ - rspec
12
+
13
+ *Goals:* Create ruby only methods that can be mixed into a class for
14
+ transforming strings to time or dates to strings. A lot of these methods
15
+ exist natively in ActiveSupport. This class isn't trying to imitate
16
+ those methods but instead is geared towards a quick well guarded, by
17
+ contracts, way of transforming back and forth.
18
+
19
+ Mostly this is a demo of the Contracts gem, but I also use these methods
20
+ in my classes so I figured I'd just create a quick gem out of them.
21
+
22
+ ## Installation
23
+
24
+ Add this line to your application's Gemfile:
25
+
26
+ ```ruby
27
+ gem 'fora'
28
+ ```
29
+
30
+ And then execute:
31
+
32
+ $ bundle
33
+
34
+ Or install it yourself as:
35
+
36
+ $ gem install fora
37
+
38
+ ## Usage
39
+
40
+ Just include these methods in your class
41
+
42
+ ```ruby
43
+ class MyAwesomeClass
44
+ include Fora
45
+
46
+ ...
47
+ end
48
+ ```
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fora. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
53
+
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
58
+
data/Rakefile ADDED
@@ -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
data/fora.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fora/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fora"
8
+ spec.version = Fora::VERSION
9
+ spec.authors = ["David Southard"]
10
+ spec.email = ["nacengineer@gmail.com"]
11
+
12
+ spec.summary = %q{Add some time manipulation to your ruby}
13
+ spec.description = %q{Simple classes to work with dates and times}
14
+ spec.homepage = "https://github.com/nacengineer/fora"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.10", ">= 1.10"
31
+ spec.add_development_dependency "rake", "~> 10.0", ">= 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.1.0", ">= 3.1.0"
33
+
34
+ spec.add_dependency "contracts", "~> 0.12.0", ">= 0.12.0"
35
+ end
@@ -0,0 +1,3 @@
1
+ module Fora
2
+ VERSION = "0.1.0"
3
+ end
data/lib/fora.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "fora/version"
2
+ require "contracts"
3
+ require "date"
4
+
5
+ module Fora
6
+ include ::Contracts
7
+ C = Contracts
8
+
9
+ protected
10
+
11
+ Contract C::Or[Date, DateTime] => String
12
+ def date_format(date)
13
+ date.strftime("%m/%d/%Y")
14
+ end
15
+
16
+ Contract C::Or[Time, DateTime] => String
17
+ def time_format(time)
18
+ time.strftime("%m-%d-%Y %H:%M")
19
+ end
20
+
21
+ # Not the most robust regex, just a quick check
22
+ Contract C::And[String, /\A[0-1][0-9]\/[0-3][0-9]\/[1-2][0-9]{3}/] \
23
+ => Date
24
+ def parse_us_date(date)
25
+ Date.strptime(date, "%m/%d/%Y")
26
+ end
27
+
28
+ # Not the most robust regex, just a quick check
29
+ Contract C::And[String, /\A[0-1][0-9]-[0-3][0-9]-[1-2][0-9]{3}\s\d{2}:\d{2}/],
30
+ C::Maybe[ C::And[String, /\A[a-zA-Z]{3}/] ] \
31
+ => Time
32
+ def parse_us_time(time, zone = "UTC")
33
+ opts = "%m-%d-%Y %H:%M %Z"
34
+ t = [time, zone].join(" ")
35
+ if zone == "UTC"
36
+ DateTime.strptime(t, opts).to_time.utc # perfer time object return
37
+ else
38
+ DateTime.strptime(t, opts).to_time
39
+ end
40
+ end
41
+
42
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fora
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Southard
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: '1.10'
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.10'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '1.10'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rake
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '10.0'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '10.0'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '10.0'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '10.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 3.1.0
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 3.1.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 3.1.0
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: 3.1.0
73
+ - !ruby/object:Gem::Dependency
74
+ name: contracts
75
+ requirement: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - "~>"
78
+ - !ruby/object:Gem::Version
79
+ version: 0.12.0
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 0.12.0
83
+ type: :runtime
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.12.0
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 0.12.0
93
+ description: Simple classes to work with dates and times
94
+ email:
95
+ - nacengineer@gmail.com
96
+ executables: []
97
+ extensions: []
98
+ extra_rdoc_files: []
99
+ files:
100
+ - ".gitignore"
101
+ - ".travis.yml"
102
+ - CODE_OF_CONDUCT.md
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - fora.gemspec
108
+ - lib/fora.rb
109
+ - lib/fora/version.rb
110
+ homepage: https://github.com/nacengineer/fora
111
+ licenses:
112
+ - MIT
113
+ metadata:
114
+ allowed_push_host: https://rubygems.org
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Add some time manipulation to your ruby
135
+ test_files: []