hublot_ar 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +1 -0
- data/hublot_ar.gemspec +23 -0
- data/lib/hublot_ar/pretty.rb +155 -0
- data/lib/hublot_ar/rails.rb +9 -0
- data/lib/hublot_ar/version.rb +3 -0
- data/lib/hublot_ar.rb +7 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjdiMDY5MWNkYWJlZDAxOTU3YjQyYzdkYzcyNmM3YTBkYmZmMGFiMQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzQ0ODgzMTUyNmFlNzYxMzFkNzhiYTAzNTgzZDUwYzU4OThlMDQxMQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDI2MDllN2I3MWU4NjM2ZmI0YjExNWVhODY1ZTU1OTNmZDAyM2IzMWJiM2Zj
|
10
|
+
OTUyYmZlZGRmM2FmMzVlZTBiOGQ0ODcxMWE2YTliNDVhMTcwNjYwY2Q0ZjVl
|
11
|
+
ZjhmNTVkYWNmZWFmZDVkMDcyZWM4MDBhODNhZmUwN2Q4MTk0ODE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzBkM2E0MTgzMzllNWMxYjE2N2Y5NDllN2UyNmIxZWIxYzNmZjlmYmY5Y2Jl
|
14
|
+
OWI3ZTc1ZmZjYTU2MjJmZjA4ZGNkOWZiNmY5YTFkMDQ4N2YzNDdmNjZmNDli
|
15
|
+
YzU5ZDNjMmRmMTFhY2U3ODQ5NmE0MjIxMGY1OTEzMWI1OTVkYWI=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Yehia Abo El-Nga
|
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,42 @@
|
|
1
|
+
# Hublot Arabic
|
2
|
+
|
3
|
+
Hublot makes Facebook-style datetime-contextual datetimes a cinch for your ActiveRecord objects.
|
4
|
+
|
5
|
+
## Examples
|
6
|
+
|
7
|
+
#### Comment created just now:
|
8
|
+
|
9
|
+
الآن
|
10
|
+
|
11
|
+
#### Comment created seconds or minutes ago
|
12
|
+
|
13
|
+
منذ ١٠ ثواني
|
14
|
+
منذ ٢ دقيقه
|
15
|
+
|
16
|
+
#### Comment created today
|
17
|
+
|
18
|
+
اليوم، الساعه ٥:٣٠ م
|
19
|
+
|
20
|
+
#### Comment created yesterday
|
21
|
+
|
22
|
+
الأمس، الساعه ٥:٣٠ م
|
23
|
+
|
24
|
+
#### Comment created this week
|
25
|
+
|
26
|
+
الأحد، الساعه ٥:٣٠ م
|
27
|
+
|
28
|
+
#### Comment created last week
|
29
|
+
|
30
|
+
الأحد الماضي، الساعه ٥:٣٠ م
|
31
|
+
|
32
|
+
## Use
|
33
|
+
|
34
|
+
gem "hublot_ar"
|
35
|
+
|
36
|
+
Call the pretty method in your views:
|
37
|
+
|
38
|
+
<%= @comment.created_at.pretty %>
|
39
|
+
|
40
|
+
## Sources
|
41
|
+
|
42
|
+
This gem is forked from brettshollenberger/Hublot. Some localization ideas were extracted from Azzurrio/hublot.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/hublot_ar.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hublot_ar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hublot_ar"
|
8
|
+
spec.version = HublotAr::VERSION
|
9
|
+
spec.authors = ["Yehia Abo El-Nga"]
|
10
|
+
spec.email = ["yehia@ewsalo.com"]
|
11
|
+
spec.description = %q{This is the arabic version of Hublot gem}
|
12
|
+
spec.summary = %q{This is the arabic version of Hublot gem}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module HublotAr
|
3
|
+
|
4
|
+
# Clock argument for testing; defaults to Time
|
5
|
+
def pretty(clock=Time.now)
|
6
|
+
@expired = (clock-self).to_i
|
7
|
+
@today = clock.strftime('%A')
|
8
|
+
@created = self.to_time.strftime('%A')
|
9
|
+
|
10
|
+
@days = {
|
11
|
+
"Monday" => 1,
|
12
|
+
"Tuesday" => 2,
|
13
|
+
"Wednesday" => 3,
|
14
|
+
"Thursday" => 4,
|
15
|
+
"Friday" => 5,
|
16
|
+
"Saturday" => 6,
|
17
|
+
"Sunday" => 7
|
18
|
+
}
|
19
|
+
|
20
|
+
@days_ar = {
|
21
|
+
"Monday" => "الإثنين",
|
22
|
+
"Tuesday" => "الثلاثاء",
|
23
|
+
"Wednesday" => "الأربعاء",
|
24
|
+
"Thursday" => "الخميس",
|
25
|
+
"Friday" => "الجمعة",
|
26
|
+
"Saturday" => "السبت",
|
27
|
+
"Sunday" => "الأحد"
|
28
|
+
}
|
29
|
+
|
30
|
+
return just_now if just_now?
|
31
|
+
return a_second_ago if a_second_ago?
|
32
|
+
return seconds_ago if seconds_ago?
|
33
|
+
return a_minute_ago if a_minute_ago?
|
34
|
+
return minutes_ago if minutes_ago?
|
35
|
+
return an_hour_ago if an_hour_ago?
|
36
|
+
return today if is_today?
|
37
|
+
return yesterday if is_yesterday?
|
38
|
+
return this_week if this_week?
|
39
|
+
return last_week if last_week?
|
40
|
+
return datetimefiesta
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def just_now
|
45
|
+
"الآن"
|
46
|
+
end
|
47
|
+
|
48
|
+
def just_now?
|
49
|
+
@expired == 0
|
50
|
+
end
|
51
|
+
|
52
|
+
def a_second_ago
|
53
|
+
"منذ ثانية"
|
54
|
+
end
|
55
|
+
|
56
|
+
def a_second_ago?
|
57
|
+
@expired == 1
|
58
|
+
end
|
59
|
+
|
60
|
+
def seconds_ago
|
61
|
+
"منذ #{ar_num @expired} ثواني"
|
62
|
+
end
|
63
|
+
|
64
|
+
def seconds_ago?
|
65
|
+
@expired >= 2 && @expired <= 59
|
66
|
+
end
|
67
|
+
|
68
|
+
def a_minute_ago
|
69
|
+
"منذ دقيقة"
|
70
|
+
end
|
71
|
+
|
72
|
+
def a_minute_ago?
|
73
|
+
@expired >= 60 && @expired <= 119 #120 = 2 minutes
|
74
|
+
end
|
75
|
+
|
76
|
+
def minutes_ago
|
77
|
+
"منذ #{ar_num (@expired/60)} دقائق"
|
78
|
+
end
|
79
|
+
|
80
|
+
def minutes_ago?
|
81
|
+
@expired >= 120 && @expired <= 3599
|
82
|
+
end
|
83
|
+
|
84
|
+
def an_hour_ago
|
85
|
+
"منذ ساعة"
|
86
|
+
end
|
87
|
+
|
88
|
+
def an_hour_ago?
|
89
|
+
@expired >= 3600 && @expired <= 7199 # 3600 = 1 hour
|
90
|
+
end
|
91
|
+
|
92
|
+
def today
|
93
|
+
"اليوم، الساعة " + localize_time(timeify)
|
94
|
+
end
|
95
|
+
|
96
|
+
def timeify
|
97
|
+
"#{self.to_time.strftime("%l:%M %p")}"
|
98
|
+
end
|
99
|
+
|
100
|
+
def is_today?
|
101
|
+
@days[@today] - @days[@created] == 0 && @expired >= 7200 && @expired <= 82800
|
102
|
+
end
|
103
|
+
|
104
|
+
def yesterday
|
105
|
+
"الأمس، الساعة " + localize_time(timeify)
|
106
|
+
end
|
107
|
+
|
108
|
+
def is_yesterday?
|
109
|
+
(@days[@today] - @days[@created] == 1 || @days[@created] + @days[@today] == 8) && @expired <= 172800
|
110
|
+
end
|
111
|
+
|
112
|
+
def this_week
|
113
|
+
localize_day(@created) + "، الساعة " + localize_time(timeify)
|
114
|
+
end
|
115
|
+
|
116
|
+
def this_week?
|
117
|
+
@expired <= 604800 && @days[@today] - @days[@created] != 0
|
118
|
+
end
|
119
|
+
|
120
|
+
def last_week
|
121
|
+
localize_day(@created) + "الماضي، الساعة " + localize_time(timeify)
|
122
|
+
end
|
123
|
+
|
124
|
+
def last_week?
|
125
|
+
@expired >= 518400 && @expired <= 1123200
|
126
|
+
end
|
127
|
+
|
128
|
+
def datetimefiesta
|
129
|
+
self.strftime("%A, %B %e at %l:%M %p")
|
130
|
+
end
|
131
|
+
|
132
|
+
def localize_time(timeify)
|
133
|
+
clock = timeify.split(' ').first.split(':').map{|e| ar_num(e.to_i)}.join(':')
|
134
|
+
time = timeify.split(' ').last == 'AM' ? "ص" : "م"
|
135
|
+
" #{clock} #{time}"
|
136
|
+
end
|
137
|
+
|
138
|
+
def localize_day(day)
|
139
|
+
@days_ar[day]
|
140
|
+
end
|
141
|
+
|
142
|
+
def ar_num(nums)
|
143
|
+
nums.to_s
|
144
|
+
.gsub('0', '٠')
|
145
|
+
.gsub('1', '١')
|
146
|
+
.gsub('2', '٢')
|
147
|
+
.gsub('3', '٣')
|
148
|
+
.gsub('4', '٤')
|
149
|
+
.gsub('5', '٥')
|
150
|
+
.gsub('6', '٦')
|
151
|
+
.gsub('7', '٧')
|
152
|
+
.gsub('8', '٨')
|
153
|
+
.gsub('9', '٩')
|
154
|
+
end
|
155
|
+
end
|
data/lib/hublot_ar.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hublot_ar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yehia Abo El-Nga
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-26 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: This is the arabic version of Hublot gem
|
42
|
+
email:
|
43
|
+
- yehia@ewsalo.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- hublot_ar.gemspec
|
54
|
+
- lib/hublot_ar.rb
|
55
|
+
- lib/hublot_ar/pretty.rb
|
56
|
+
- lib/hublot_ar/rails.rb
|
57
|
+
- lib/hublot_ar/version.rb
|
58
|
+
homepage: ''
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.1.4
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: This is the arabic version of Hublot gem
|
82
|
+
test_files: []
|