rbprayertime 0.1.5 → 0.1.9.1

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.
Files changed (4) hide show
  1. data/ChangeLog +17 -0
  2. data/bin/prayertimes +102 -0
  3. data/lib/prayertime.rb +44 -41
  4. metadata +23 -42
data/ChangeLog ADDED
@@ -0,0 +1,17 @@
1
+ [*] 2010-12-6
2
+ - Initial relese :)
3
+
4
+ [*] 2011-2-6
5
+ - two bug fixes (into to_hrtime method)
6
+ - just use % in remove_duplication()
7
+ - add as_rbtime method to get string formatted time with ruby time
8
+ - add more comments
9
+
10
+ [*] 2013-7-29
11
+ - remove season and add dst instead
12
+ - a simple cli (prayertimes executable)
13
+ - will be rewritten
14
+ - latitude is written first
15
+
16
+ [*] 2013-7-30
17
+ - fix doc and version
data/bin/prayertimes ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ require 'prayertime'
4
+ # cairo > lat, lon => 29.7768, 31.3101
5
+ clat, clon = 29.7768, 31.3101 #30.1, 31.41667 ??
6
+
7
+ require 'optparse'
8
+ require 'optparse/date'
9
+ require 'ostruct'
10
+
11
+ opts = OpenStruct.new
12
+
13
+ opts_parser = OptionParser.new do |optp|
14
+ optp.banner = "Usage: #{__FILE__} [options]..."
15
+ optp.version = Prayertime::VERSION
16
+
17
+ optp.separator ""
18
+ optp.separator "location coordinates options: "
19
+
20
+ # FIXME: use coordinates instead (after being fixed in lib)
21
+ optp.on("--lat Latitude", Float, "latitude, default 31.3101") do |lat|
22
+ opts.lat = lat
23
+ end
24
+
25
+ optp.on("--lon Longitude", Float, "longitude, default 29.7768") do |lon|
26
+ opts.lon = lon
27
+ end
28
+
29
+ optp.on("-z", "--zone Zone", Float, "time zone, default: 2") do |zone|
30
+ opts.zone = zone
31
+ end
32
+
33
+ optp.separator ""
34
+ optp.separator "date: "
35
+
36
+ optp.on("-d", "--date [Date], date", Date, "chosen date, yyyy/mm/dd, default: today") do |date|
37
+ opts.date = date
38
+ end
39
+
40
+
41
+ optp.separator ""
42
+ optp.separator "calculation options: "
43
+
44
+ optp.on("-c", "--calendar N", Integer, "calculation method",
45
+ "0: Umm Al Qura Univ",
46
+ "1: Egyptian General Authority Of Survey",
47
+ "2: Univ Of Islamic Sciences Karachi",
48
+ "3: Islamic Society Of North America",
49
+ "4: Muslim World League") do |cal|
50
+ opts.calendar = cal
51
+ end
52
+
53
+ optp.separator ""
54
+
55
+ optp.on("-m", "--mazhab N", Integer, "chosen mazhab", "0: Default", "1: Hanafi") do |mazhab|
56
+ opts.mazhab = mazhab
57
+ end
58
+
59
+ optp.separator ""
60
+
61
+ #it should be dst
62
+ optp.on("-s", "--dst Hours", Float, "daylight saving time, default: 0", ) do |dst|
63
+ opts.dst = dst# || 0
64
+ end
65
+
66
+ optp.separator ""
67
+ optp.separator "common options:"
68
+
69
+ optp.on("-h", "--help", "show this message") do |season|
70
+ puts optp
71
+ exit
72
+ end
73
+
74
+ optp.on("-v", "--version", "prayertimes version") do |season|
75
+ puts "prayertimes library for ruby, version: #{Prayertime::VERSION}"
76
+ exit
77
+ end
78
+ end
79
+
80
+ opts_parser.accept(Float)
81
+ opts_parser.parse!(ARGV)
82
+
83
+ # why?!!
84
+ opts.lat = opts.lat || clat
85
+ opts.lon = opts.lon || clon
86
+ opts.zone = opts.zone || 2
87
+ opts.calendar = opts.calendar || Calendar::EgyptianGeneralAuthorityOfSurvey
88
+ opts.mazhab = opts.mazhab || Mazhab::Default
89
+ opts.dst = opts.dst || 0
90
+ opts.date = opts.date || Date.today
91
+
92
+ year, month, day = opts.date.year, opts.date.month, opts.date.day
93
+
94
+ pt = Prayertime.new(opts.lat, opts.lon, opts.zone, year, month, day, opts.calendar, opts.mazhab, opts.dst)
95
+
96
+ puts "Location: [#{opts.lat}, #{opts.lon}]"
97
+ puts "Date: #{opts.date.strftime("%Y/%m/%d")}"
98
+
99
+ #pt.calculate()
100
+ pt.report()
101
+ puts "Qibla: " + pt.qibla.to_s + "° N"
102
+ puts "Distance to kaaba: " + pt.qibla_distance.to_s + " km"
data/lib/prayertime.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # coding: utf-8
3
- #
3
+ # TODO: rewrite with more explanations (also port PrayTimes.js)
4
4
  # Prayertimes implementation for ruby - just a port of pyprayertime.
5
5
  #
6
6
  # Author: Abdelrahman ghanem <abom.jdev@gmail.com>.
@@ -41,10 +41,10 @@ def remove_duplication(var)
41
41
  var % 360
42
42
  end
43
43
 
44
- # A class represents seasons for day light saving time -dst-.
45
- class Season
46
- Winter, Summer = 0, 1
47
- end
44
+ # # A class represents seasons for day light saving time -dst-.
45
+ # class Season
46
+ # Winter, Summer = 0, 1
47
+ # end
48
48
 
49
49
  # A class represents calculation calendars.
50
50
  class Calendar
@@ -52,7 +52,7 @@ class Calendar
52
52
  EgyptianGeneralAuthorityOfSurvey,
53
53
  UnivOfIslamicSciencesKarachi,
54
54
  IslamicSocietyOfNorthAmerica,
55
- MuslimWorldLeague = (1..5).to_a
55
+ MuslimWorldLeague = (0...5).to_a
56
56
  end
57
57
 
58
58
  # A class represents mazhab -asr time difference only-.
@@ -61,7 +61,7 @@ class Mazhab
61
61
  end
62
62
 
63
63
  # A String formatted time: %I:%M:%S %p.
64
- def to_hrtime(var, isAM = false)
64
+ def to_hrtime(var, isAM = false)
65
65
  # var: double -> human readable string of format "%I:%M:%S %p"
66
66
  time = ''
67
67
  intvar = var.to_i #var is double.
@@ -123,9 +123,9 @@ class Coordinate
123
123
  attr :latitude, true
124
124
  attr :zone, true
125
125
 
126
- def initialize(longitude, latitude, zone)
127
- @longitude = longitude
126
+ def initialize(latitude, longitude, zone)
128
127
  @latitude = latitude
128
+ @longitude = longitude
129
129
  @zone = zone
130
130
  end
131
131
 
@@ -133,13 +133,14 @@ end
133
133
 
134
134
  # Prayertime class, containing calculations, prayer times...etc.
135
135
  class Prayertime
136
-
136
+ VERSION = '0.1.9.1'
137
137
  # Initialize a new prayertime object.
138
138
  #
139
139
  # Usage example:
140
140
  #
141
- # #cairo > lat,lon => 31.3101, 29.7768
142
- # pt=Prayertime.new(31.3101, 29.7768, 2, 2011, 2, 7, Calendar::EgyptianGeneralAuthorityOfSurvey, Mazhab::Default, Season::Winter)
141
+ # # cairo => lat,lon => 29.7768, 31.3101
142
+ # # dst => one hour
143
+ # pt=Prayertime.new(29.7768, 31.3101, 2, 2011, 2, 7, Calendar::EgyptianGeneralAuthorityOfSurvey, Mazhab::Default, 1)
143
144
  # pt.report()
144
145
  # puts pt.qibla.to_s + "° N"
145
146
  # puts pt.qibla_distance.to_s + " km"
@@ -153,17 +154,26 @@ class Prayertime
153
154
  # 135.489731310865° N
154
155
  # 1262.14097579674 km
155
156
 
156
- def initialize(longitude, latitude, zone,
157
+ # TODO: use attributes directly
158
+ # remove ostruct when parsing options
159
+ # attr_accessor :coordinate
160
+ # attr_accessor :date
161
+ # attr_accessor :calendar
162
+ # attr_accessor :mazhab
163
+ # attr_accessor :dst
164
+
165
+ def initialize(latitude, longitude, zone,
157
166
  year, month, day,
158
167
  cal=Calendar::UmmAlQuraUniv,
159
168
  mazhab=Mazhab::Default,
160
- season=Season::Winter)
169
+ dst=nil)
161
170
 
162
- @coordinate = Coordinate.new(longitude, latitude, zone)
171
+ @coordinate = Coordinate.new(latitude, longitude, zone)
163
172
  @date = Date.new(year, month, day)
164
173
  @calendar = cal
165
174
  @mazhab = mazhab
166
- @season = season
175
+ #@season = season
176
+ @dst = dst
167
177
  @shrouk = nil
168
178
  @fajr = nil
169
179
  @zuhr = nil
@@ -210,8 +220,8 @@ class Prayertime
210
220
  year = @date.year
211
221
  month = @date.month
212
222
  day = @date.day
213
- longitude = @coordinate.longitude
214
223
  latitude = @coordinate.latitude
224
+ longitude = @coordinate.longitude
215
225
  zone = @coordinate.zone
216
226
  julian_day = (367*year)-(((year+((month+9)/12).to_i)*7)/4).to_i+(275*month/9).to_i+day-730531.5
217
227
  sun_length = 280.461+0.9856474*julian_day
@@ -282,13 +292,15 @@ class Prayertime
282
292
  asr = local_noon+equation(asr_alt)/15 # Asr Time.
283
293
 
284
294
  #Add one hour to all times if the season is Summmer.
285
- if @season == Season::Summer
286
- fajr += 1
287
- shrouk += 1
288
- zuhr += 1
289
- asr += 1
290
- maghrib += 1
291
- isha += 1
295
+ # FIXME: DST: daylight saving time not usually equals one hour in all countries/cities,
296
+ #also not all of them apply dst.
297
+ unless @dst
298
+ fajr += @dst
299
+ shrouk += @dst
300
+ zuhr += @dst
301
+ asr += @dst
302
+ maghrib += @dst
303
+ isha += @dst
292
304
  end
293
305
 
294
306
  @shrouk = shrouk
@@ -308,11 +320,11 @@ class Prayertime
308
320
  # Return qibla angle from north (in degrees).
309
321
  def qibla
310
322
 
311
- k_lat = radians(21.423333);
312
- k_lon = radians(39.823333);
313
-
314
- longitude = radians(@coordinate.longitude)
323
+ k_lat = radians(21.423333)
324
+ k_lon = radians(39.823333)
325
+
315
326
  latitude = radians(@coordinate.latitude)
327
+ longitude = radians(@coordinate.longitude)
316
328
 
317
329
  numerator = sin(k_lon - longitude)
318
330
  denominator = (cos(latitude) * tan(k_lat)) - (sin(latitude) * cos(k_lon - longitude))
@@ -325,11 +337,11 @@ class Prayertime
325
337
  # The distance to kaaba in kilometers.
326
338
  def qibla_distance
327
339
 
328
- k_lat = radians(21.423333);
329
- k_lon = radians(39.823333);
330
-
331
- longitude = radians(@coordinate.longitude)
340
+ k_lat = radians(21.423333)
341
+ k_lon = radians(39.823333)
342
+
332
343
  latitude = radians(@coordinate.latitude)
344
+ longitude = radians(@coordinate.longitude)
333
345
 
334
346
  r = 6378.7 #kilometers
335
347
 
@@ -347,13 +359,4 @@ class Prayertime
347
359
  puts "Ishaa Time is #{isha_time}"
348
360
  end
349
361
 
350
- end
351
-
352
- if $0 == __FILE__
353
- #cairo > lat,lon => 31.3101, 29.7768
354
- pt=Prayertime.new(31.3101, 29.7768, 2, 2011, 2, 7, Calendar::EgyptianGeneralAuthorityOfSurvey, Mazhab::Default, Season::Winter)
355
- #pt.calculate()
356
- pt.report()
357
- puts pt.qibla.to_s + "° N"
358
- puts pt.qibla_distance.to_s + " km"
359
362
  end
metadata CHANGED
@@ -1,67 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rbprayertime
3
- version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 1
9
- - 5
10
- version: 0.1.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.9.1
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Abdelrahman Ghanem
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-02-07 00:00:00 +02:00
19
- default_executable:
12
+ date: 2013-07-30 00:00:00.000000000 Z
20
13
  dependencies: []
21
-
22
14
  description: A ruby port of pyprayertime (prayertime algorithm implementation in python).
23
15
  email: abom.jdev@gmail.com
24
- executables: []
25
-
16
+ executables:
17
+ - prayertimes
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
20
+ files:
31
21
  - lib/prayertime.rb
32
- has_rdoc: true
22
+ - bin/prayertimes
23
+ - ChangeLog
33
24
  homepage: http://bitbucket.org/abom/rbprayertime
34
25
  licenses: []
35
-
36
26
  post_install_message:
37
27
  rdoc_options: []
38
-
39
- require_paths:
28
+ require_paths:
40
29
  - lib
41
- required_ruby_version: !ruby/object:Gem::Requirement
30
+ required_ruby_version: !ruby/object:Gem::Requirement
42
31
  none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- hash: 3
47
- segments:
48
- - 0
49
- version: "0"
50
- required_rubygems_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
37
  none: false
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- hash: 3
56
- segments:
57
- - 0
58
- version: "0"
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
59
42
  requirements: []
60
-
61
43
  rubyforge_project: rbprayertime
62
- rubygems_version: 1.3.7
44
+ rubygems_version: 1.8.23
63
45
  signing_key:
64
46
  specification_version: 3
65
47
  summary: A ruby port of pyprayertime.
66
48
  test_files: []
67
-