ventana 0.9.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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +10 -0
- data/lib/ventana/i18n.rb +8 -0
- data/lib/ventana/locales/en.yml +32 -0
- data/lib/ventana/locales/es.yml +32 -0
- data/lib/ventana/method.rb +87 -0
- data/lib/ventana/version.rb +3 -0
- data/lib/ventana.rb +2 -0
- data/test/examples.csv +11 -0
- data/test/examples_test.rb +18 -0
- data/test/method_test.rb +36 -0
- data/test/test_helper.rb +7 -0
- data/ventana.gemspec +24 -0
- metadata +107 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3141723af739ed9cadf77a14e0a8fe5d48b7f0d9
|
4
|
+
data.tar.gz: 868d62c8112050f4d5d3bdb77d58e27187e0e927
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aa8dfcac6a0972813039ef474e02928837d3046b583a13dea27e8516cab8428f7cad603ba572e3a0aff539bb1cef5fa95a6dcc0c2efad5b91de3d53cf1053894
|
7
|
+
data.tar.gz: ca602a803454aeea263ab037fe7305ebc632bf71e02f77f008f788188f0edf205a929896c488c2bd29558d1718bd3d4c5e524472d92e281058981249c0cfdbc5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Seba Gamboa
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Ventana
|
2
|
+
|
3
|
+
Ventana takes two dates and gives you a nice string with the window between those two dates
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ventana'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ventana
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Just pass two dates to the `Ventana` method and get back a string with the window between those two dates.
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
date1 = Time.new(2014,6,3,4)
|
25
|
+
date2 = Time.new(2014,6,4,7)
|
26
|
+
|
27
|
+
puts Ventana(date1,date2)
|
28
|
+
# => June 3 to 4, 2014 from 4AM to 7AM
|
29
|
+
```
|
30
|
+
|
31
|
+
For more exeamples of how different times and dates are rendered check out the [example file](https://github.com/sagmor/ventana/blob/master/test/examples.csv).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it ( http://github.com/sagmor/ventana/fork )
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/ventana/i18n.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
en:
|
2
|
+
ventana:
|
3
|
+
full_dates_with_days: "%{from_month} %{from_day}, %{from_year} to %{to_month} %{to_day}, %{to_year}"
|
4
|
+
full_dates_without_days: "%{from_month} %{from_year} to %{to_month} %{from_year}"
|
5
|
+
single_year_with_days: "%{from_month} %{from_day} to %{to_month} %{to_day}, %{from_year}"
|
6
|
+
single_year_without_days: "%{from_month} to %{to_month} %{from_year}"
|
7
|
+
single_month_with_days: "%{from_month} %{from_day} to %{to_day}, %{from_year}"
|
8
|
+
single_month_without_days: "%{from_month} %{from_year}"
|
9
|
+
single_day: "%{from_month} %{from_day}, %{from_year}"
|
10
|
+
time_difference: "from %{from_time} to %{to_time}"
|
11
|
+
day_names:
|
12
|
+
- Sunday
|
13
|
+
- Monday
|
14
|
+
- Tuesday
|
15
|
+
- Wednesday
|
16
|
+
- Thursday
|
17
|
+
- Friday
|
18
|
+
- Saturday
|
19
|
+
month_names:
|
20
|
+
-
|
21
|
+
- January
|
22
|
+
- February
|
23
|
+
- March
|
24
|
+
- April
|
25
|
+
- May
|
26
|
+
- June
|
27
|
+
- July
|
28
|
+
- August
|
29
|
+
- September
|
30
|
+
- October
|
31
|
+
- November
|
32
|
+
- December
|
@@ -0,0 +1,32 @@
|
|
1
|
+
es:
|
2
|
+
ventana:
|
3
|
+
full_dates_with_days: "%{from_day} de %{from_month} del %{from_year} a %{to_day} de %{to_month} del %{to_year}"
|
4
|
+
full_dates_without_days: "%{from_month} del %{from_year} a %{to_month} del %{from_year}"
|
5
|
+
single_year_with_days: "%{from_day} de %{from_month} al %{to_day} de %{to_month} del %{from_year}"
|
6
|
+
single_year_without_days: "%{from_month} a %{to_month} del %{from_year}"
|
7
|
+
single_month_with_days: "%{from_day} al %{to_day} de %{from_month} del %{from_year}"
|
8
|
+
single_month_without_days: "%{from_month} del %{from_year}"
|
9
|
+
single_day: "%{from_day} de %{from_month} del %{from_year}"
|
10
|
+
time_difference: "entre %{from_time} y %{to_time}"
|
11
|
+
day_names:
|
12
|
+
- domingo
|
13
|
+
- lunes
|
14
|
+
- martes
|
15
|
+
- miércoles
|
16
|
+
- jueves
|
17
|
+
- viernes
|
18
|
+
- sábado
|
19
|
+
month_names:
|
20
|
+
-
|
21
|
+
- enero
|
22
|
+
- febrero
|
23
|
+
- marzo
|
24
|
+
- abril
|
25
|
+
- mayo
|
26
|
+
- junio
|
27
|
+
- julio
|
28
|
+
- agosto
|
29
|
+
- septiembre
|
30
|
+
- octubre
|
31
|
+
- noviembre
|
32
|
+
- diciembre
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'ventana/i18n'
|
2
|
+
|
3
|
+
module Ventana
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def date_format(from,to)
|
7
|
+
format = if to.year > from.year
|
8
|
+
# must show year difference
|
9
|
+
"full_dates"
|
10
|
+
elsif to.month > from.month
|
11
|
+
# must show month difference
|
12
|
+
"single_year"
|
13
|
+
elsif to.day > from.day
|
14
|
+
# within the same month
|
15
|
+
"single_month"
|
16
|
+
else
|
17
|
+
# within the same day
|
18
|
+
"single_day"
|
19
|
+
end
|
20
|
+
|
21
|
+
if Ventana.show_days?(from,to)
|
22
|
+
format << "_with_days"
|
23
|
+
else
|
24
|
+
format << "_without_days"
|
25
|
+
end unless format == "single_day"
|
26
|
+
|
27
|
+
format
|
28
|
+
end
|
29
|
+
|
30
|
+
def time_format(from,to)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def show_days?(from,to)
|
35
|
+
from.day != 1 || to.day != case to.month
|
36
|
+
when 1,3,5,7,8,10,12 then 31
|
37
|
+
when 4,6,9,11 then 30
|
38
|
+
else
|
39
|
+
if (to.year % 4) == 0
|
40
|
+
29
|
41
|
+
else
|
42
|
+
28
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def time_format(date)
|
48
|
+
str = date.strftime "%l"
|
49
|
+
if date.min > 0
|
50
|
+
str << ":" << date.strftime("%M")
|
51
|
+
end
|
52
|
+
str << "" << date.strftime("%p")
|
53
|
+
|
54
|
+
str.strip
|
55
|
+
end
|
56
|
+
|
57
|
+
def show_time?(from,to)
|
58
|
+
from.hour != 0 ||
|
59
|
+
from.minutes != 0 ||
|
60
|
+
from.seconds != 0 ||
|
61
|
+
to.hour != 12 ||
|
62
|
+
to.minutes != 0 ||
|
63
|
+
to.seconds != 0
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def Ventana(from,to,options={})
|
68
|
+
raise ArgumentError, "#{from} is bigger than #{to}" if from > to
|
69
|
+
|
70
|
+
date = I18n.t(Ventana.date_format(from,to), {
|
71
|
+
from_year: from.year,
|
72
|
+
from_month: I18n.t('ventana.month_names')[from.month],
|
73
|
+
from_day: from.day,
|
74
|
+
to_year: to.year,
|
75
|
+
to_month: I18n.t('ventana.month_names')[to.month],
|
76
|
+
to_day: to.day,
|
77
|
+
scope: :ventana
|
78
|
+
})
|
79
|
+
|
80
|
+
time = I18n.t(:time_difference, {
|
81
|
+
from_time: Ventana.time_format(from),
|
82
|
+
to_time: Ventana.time_format(to),
|
83
|
+
scope: :ventana,
|
84
|
+
})
|
85
|
+
|
86
|
+
[date, time].join(' ')
|
87
|
+
end
|
data/lib/ventana.rb
ADDED
data/test/examples.csv
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
locale,from,to,expectation
|
2
|
+
en,2014-06-06 12:00:00,2014-06-06 15:00:00,"June 6, 2014 from 12PM to 3PM"
|
3
|
+
en,2014-06-05 12:00:00,2014-06-10 15:00:00,"June 5 to 10, 2014 from 12PM to 3PM"
|
4
|
+
en,2014-06-01 12:00:00,2014-06-30 15:00:00,"June 2014 from 12PM to 3PM"
|
5
|
+
en,2014-06-01 12:00:00,2014-07-31 15:00:00,"June to July 2014 from 12PM to 3PM"
|
6
|
+
en,2014-06-05 12:00:00,2014-07-10 15:00:00,"June 5 to July 10, 2014 from 12PM to 3PM"
|
7
|
+
es,2014-06-06 12:00:00,2014-06-06 15:00:00,"6 de junio del 2014 entre 12PM y 3PM"
|
8
|
+
es,2014-06-05 12:00:00,2014-06-10 15:00:00,"5 al 10 de junio del 2014 entre 12PM y 3PM"
|
9
|
+
es,2014-06-01 12:00:00,2014-06-30 15:00:00,"junio del 2014 entre 12PM y 3PM"
|
10
|
+
es,2014-06-01 12:00:00,2014-07-31 15:00:00,"junio a julio del 2014 entre 12PM y 3PM"
|
11
|
+
es,2014-06-05 12:00:00,2014-07-10 15:00:00,"5 de junio al 10 de julio del 2014 entre 12PM y 3PM"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'csv'
|
3
|
+
require 'time'
|
4
|
+
|
5
|
+
# This test case runs all the examples from the examples.csv file
|
6
|
+
class ExampleTest < TestCase
|
7
|
+
|
8
|
+
CSV.foreach(File.expand_path('../examples.csv',__FILE__),{
|
9
|
+
headers: true
|
10
|
+
}).each_with_index do |row, index|
|
11
|
+
define_method "test_example_#{index + 1}" do
|
12
|
+
I18n.with_locale row['locale'] do
|
13
|
+
assert_equal row['expectation'], Ventana(Time.parse(row['from']), Time.parse(row['to']))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/test/method_test.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
class MethodTest < TestCase
|
2
|
+
TEST_FROM = Time.new(2014,6,3)
|
3
|
+
TEST_TO = Time.new(2014,6,4)
|
4
|
+
|
5
|
+
|
6
|
+
def test_ventana_method_existence
|
7
|
+
assert Ventana(TEST_FROM,TEST_TO)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_must_show_days?
|
11
|
+
[
|
12
|
+
[[2014,6,3], [2014,6,4]],
|
13
|
+
[[2016,2,1],[2016,2,28]]
|
14
|
+
].each do |from,to|
|
15
|
+
assert Ventana.show_days?(Time.new(*from), Time.new(*to))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_must_not_show_days?
|
20
|
+
[
|
21
|
+
[[2016,2,1],[2016,2,29]],
|
22
|
+
[[2014,2,1],[2014,2,28]],
|
23
|
+
[[2014,6,1],[2014,6,30]],
|
24
|
+
[[2014,6,1],[2014,7,31]]
|
25
|
+
].each do |from,to|
|
26
|
+
assert !Ventana.show_days?(Time.new(*from), Time.new(*to))
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_dates_must_must_be_passed_in_the_correct_order
|
32
|
+
assert_raises(ArgumentError){ Ventana(TEST_TO,TEST_FROM) }
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
data/test/test_helper.rb
ADDED
data/ventana.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ventana/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ventana"
|
8
|
+
spec.version = Ventana::VERSION
|
9
|
+
spec.authors = ["Seba Gamboa"]
|
10
|
+
spec.email = ["me@sagmor.com"]
|
11
|
+
spec.summary = %q{Ventana makes window strings}
|
12
|
+
spec.description = %q{Ventana takes two dates and gives you a nice string with the window between those two dates}
|
13
|
+
spec.homepage = "https://github.com/sagmor/ventana"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "i18n"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ventana
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Seba Gamboa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-09 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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Ventana takes two dates and gives you a nice string with the window between
|
56
|
+
those two dates
|
57
|
+
email:
|
58
|
+
- me@sagmor.com
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- lib/ventana.rb
|
69
|
+
- lib/ventana/i18n.rb
|
70
|
+
- lib/ventana/locales/en.yml
|
71
|
+
- lib/ventana/locales/es.yml
|
72
|
+
- lib/ventana/method.rb
|
73
|
+
- lib/ventana/version.rb
|
74
|
+
- test/examples.csv
|
75
|
+
- test/examples_test.rb
|
76
|
+
- test/method_test.rb
|
77
|
+
- test/test_helper.rb
|
78
|
+
- ventana.gemspec
|
79
|
+
homepage: https://github.com/sagmor/ventana
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Ventana makes window strings
|
103
|
+
test_files:
|
104
|
+
- test/examples.csv
|
105
|
+
- test/examples_test.rb
|
106
|
+
- test/method_test.rb
|
107
|
+
- test/test_helper.rb
|