prayertimes 1.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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/lib/prayertimes/version.rb +3 -0
- data/lib/prayertimes.rb +442 -0
- data/prayertimes.gemspec +24 -0
- data/spec/prayertimes_spec.rb +16 -0
- data/spec/spec_helper.rb +1 -0
- metadata +98 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 56620c9087706a7cf2587e61a8c3520ccb59f3fb
         | 
| 4 | 
            +
              data.tar.gz: aa161d67cf5d43364f47387be41d8495afb68a37
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: f2bdec48edae509663daa91c5cc10bd6631e338d29bc5afd2eb2583084c9710b0ae6439d552acfbe1f6f6603e52a6e280e51d06513c0658691e8489f9046f654
         | 
| 7 | 
            +
              data.tar.gz: 80fe5afe07e86af212fa51954a0a1f6ca7f76292559a0632e3a5bcfc9873f3bb02851e4009cf70b88d3755499e4628e105d47b45c3e1f3660101a4ba7a979f65
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,22 @@ | |
| 1 | 
            +
            Copyright (c) 2014 Mohamed El Mahallawy
         | 
| 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,31 @@ | |
| 1 | 
            +
            # Prayertimes
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            TODO: Write a gem description
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Installation
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            Add this line to your application's Gemfile:
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            ```ruby
         | 
| 10 | 
            +
            gem 'prayertimes'
         | 
| 11 | 
            +
            ```
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            And then execute:
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                $ bundle
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            Or install it yourself as:
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                $ gem install prayertimes
         | 
| 20 | 
            +
             | 
| 21 | 
            +
            ## Usage
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            TODO: Write usage instructions here
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            ## Contributing
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            1. Fork it ( https://github.com/[my-github-username]/prayertimes/fork )
         | 
| 28 | 
            +
            2. Create your feature branch (`git checkout -b my-new-feature`)
         | 
| 29 | 
            +
            3. Commit your changes (`git commit -am 'Add some feature'`)
         | 
| 30 | 
            +
            4. Push to the branch (`git push origin my-new-feature`)
         | 
| 31 | 
            +
            5. Create a new Pull Request
         | 
    
        data/Rakefile
    ADDED
    
    
    
        data/lib/prayertimes.rb
    ADDED
    
    | @@ -0,0 +1,442 @@ | |
| 1 | 
            +
            require "prayertimes/version"
         | 
| 2 | 
            +
            require "date"
         | 
| 3 | 
            +
            module Prayertimes
         | 
| 4 | 
            +
            	class Prayertimes
         | 
| 5 | 
            +
             | 
| 6 | 
            +
             | 
| 7 | 
            +
            		# Names of the times
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            		@@timeNames = {
         | 
| 10 | 
            +
            			'imsak'    => 'Imsak',
         | 
| 11 | 
            +
            			'fajr'     => 'Fajr',
         | 
| 12 | 
            +
            			'sunrise'  => 'Sunrise',
         | 
| 13 | 
            +
            			'dhuhr'    => 'Dhuhr',
         | 
| 14 | 
            +
            			'asr'      => 'Asr',
         | 
| 15 | 
            +
            			'sunset'   => 'Sunset',
         | 
| 16 | 
            +
            			'maghrib'  => 'Maghrib',
         | 
| 17 | 
            +
            			'isha'     => 'Isha',
         | 
| 18 | 
            +
            			'midnight' => 'Midnight'
         | 
| 19 | 
            +
            		}
         | 
| 20 | 
            +
             | 
| 21 | 
            +
             | 
| 22 | 
            +
             | 
| 23 | 
            +
            		# Calculation Methods
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            		@@methods = {
         | 
| 26 | 
            +
            			'MWL'=> {
         | 
| 27 | 
            +
            				'name'=> 'Muslim World League',
         | 
| 28 | 
            +
            				'params'=> { 'fajr'=> 18, 'isha'=> 17 } },
         | 
| 29 | 
            +
            				'ISNA'=> {
         | 
| 30 | 
            +
            					'name'=> 'Islamic Society of North America (ISNA)',
         | 
| 31 | 
            +
            					'params'=> { 'fajr'=> 15, 'isha'=> 15 } },
         | 
| 32 | 
            +
            					'Egypt'=> {
         | 
| 33 | 
            +
            						'name'=> 'Egyptian General Authority of Survey',
         | 
| 34 | 
            +
            						'params'=> { 'fajr'=> 19.5, 'isha'=> 17.5 } },
         | 
| 35 | 
            +
            						'Makkah'=> {
         | 
| 36 | 
            +
            							'name'=> 'Umm Al-Qura University, Makkah',
         | 
| 37 | 
            +
            				'params'=> { 'fajr'=> 18.5, 'isha'=> '90 min' } },  # fajr was 19 degrees before 1430 hijri
         | 
| 38 | 
            +
            				'Karachi'=> {
         | 
| 39 | 
            +
            					'name'=> 'University of Islamic Sciences, Karachi',
         | 
| 40 | 
            +
            					'params'=> { 'fajr'=> 18, 'isha'=> 18 } },
         | 
| 41 | 
            +
            					'Tehran'=> {
         | 
| 42 | 
            +
            						'name'=> 'Institute of Geophysics, University of Tehran',
         | 
| 43 | 
            +
            				'params'=> { 'fajr'=> 17.7, 'isha'=> 14, 'maghrib'=> 4.5, 'midnight'=> 'Jafari' } },  # isha is not explicitly specified in this method
         | 
| 44 | 
            +
            				'Jafari'=> {
         | 
| 45 | 
            +
            					'name'=> 'Shia Ithna-Ashari, Leva Institute, Qum',
         | 
| 46 | 
            +
            					'params'=> { 'fajr'=> 16, 'isha'=> 14, 'maghrib'=> 4, 'midnight'=> 'Jafari' } }
         | 
| 47 | 
            +
            				}
         | 
| 48 | 
            +
             | 
| 49 | 
            +
             | 
| 50 | 
            +
            		# Default Parameters in Calculation Methods
         | 
| 51 | 
            +
             | 
| 52 | 
            +
            		@@defaultParams = {
         | 
| 53 | 
            +
            			'maghrib'=> '0 min', 'midnight'=> 'Standard'
         | 
| 54 | 
            +
            		}
         | 
| 55 | 
            +
             | 
| 56 | 
            +
             | 
| 57 | 
            +
             | 
| 58 | 
            +
            		#---------------------- Default Settings --------------------
         | 
| 59 | 
            +
             | 
| 60 | 
            +
             | 
| 61 | 
            +
            		@@calcMethod = 'MWL'
         | 
| 62 | 
            +
             | 
| 63 | 
            +
             | 
| 64 | 
            +
            		# do not change anything here; use adjust method instead
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            		@@settings = {
         | 
| 67 | 
            +
            			"imsak"    => '10 min',
         | 
| 68 | 
            +
            			"dhuhr"    => '0 min',
         | 
| 69 | 
            +
            			"asr"      => 'Standard',
         | 
| 70 | 
            +
            			"highLats" => 'NightMiddle'
         | 
| 71 | 
            +
            		}
         | 
| 72 | 
            +
             | 
| 73 | 
            +
             | 
| 74 | 
            +
             | 
| 75 | 
            +
            		@@timeFormat = '24h'
         | 
| 76 | 
            +
             | 
| 77 | 
            +
             | 
| 78 | 
            +
             | 
| 79 | 
            +
            		@@timeSuffixes = ['am', 'pm']
         | 
| 80 | 
            +
             | 
| 81 | 
            +
             | 
| 82 | 
            +
             | 
| 83 | 
            +
            		@@invalidTime =  '-----'
         | 
| 84 | 
            +
             | 
| 85 | 
            +
             | 
| 86 | 
            +
             | 
| 87 | 
            +
            		@@numIterations = 1
         | 
| 88 | 
            +
             | 
| 89 | 
            +
             | 
| 90 | 
            +
             | 
| 91 | 
            +
            		@@offset = {}
         | 
| 92 | 
            +
             | 
| 93 | 
            +
             | 
| 94 | 
            +
             | 
| 95 | 
            +
            		#---------------------- Initialization -----------------------
         | 
| 96 | 
            +
            		
         | 
| 97 | 
            +
            		def initialize(method = "MWL")
         | 
| 98 | 
            +
            			@@methods.each do |method, config|
         | 
| 99 | 
            +
            				@@defaultParams.each do |name, value|
         | 
| 100 | 
            +
            					# if name in config['params'] || config['params'][name] != nil
         | 
| 101 | 
            +
            					config['params'][name] = value
         | 
| 102 | 
            +
            					# end
         | 
| 103 | 
            +
            				end
         | 
| 104 | 
            +
            			end
         | 
| 105 | 
            +
             | 
| 106 | 
            +
            			@@calcMethod = method #if method in @@methods else 'MWL'
         | 
| 107 | 
            +
             | 
| 108 | 
            +
            			params = @@methods[@@calcMethod]['params']
         | 
| 109 | 
            +
            			params.each do |name, value|
         | 
| 110 | 
            +
            				@@settings[name] = value
         | 
| 111 | 
            +
            			end
         | 
| 112 | 
            +
             | 
| 113 | 
            +
            			@@timeNames.each do |name, value|
         | 
| 114 | 
            +
            				@@offset[name] = 0
         | 
| 115 | 
            +
            			end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
            		end
         | 
| 118 | 
            +
             | 
| 119 | 
            +
             | 
| 120 | 
            +
            		#-------------------- Interface Functions --------------------
         | 
| 121 | 
            +
             | 
| 122 | 
            +
            		def setMethod(method)
         | 
| 123 | 
            +
            			if @@methods[method]
         | 
| 124 | 
            +
            				self.adjust(@@methods[method].params)
         | 
| 125 | 
            +
            				self.calcMethod = method
         | 
| 126 | 
            +
            			end
         | 
| 127 | 
            +
            		end
         | 
| 128 | 
            +
             | 
| 129 | 
            +
            		def adjust(params)
         | 
| 130 | 
            +
            			@@settings.update(params)
         | 
| 131 | 
            +
            		end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
            		def tune(timeOffsets)
         | 
| 134 | 
            +
            			@@offset.update(timeOffsets)
         | 
| 135 | 
            +
            		end
         | 
| 136 | 
            +
             | 
| 137 | 
            +
            		def getMethod
         | 
| 138 | 
            +
            			return @@calcMethod
         | 
| 139 | 
            +
            		end
         | 
| 140 | 
            +
             | 
| 141 | 
            +
            		def getSettings
         | 
| 142 | 
            +
            			return @@settings
         | 
| 143 | 
            +
            		end
         | 
| 144 | 
            +
             | 
| 145 | 
            +
            		def getOffsets
         | 
| 146 | 
            +
            			return @@offset
         | 
| 147 | 
            +
            		end
         | 
| 148 | 
            +
             | 
| 149 | 
            +
            		def getDefaults
         | 
| 150 | 
            +
            			return @@methods
         | 
| 151 | 
            +
            		end
         | 
| 152 | 
            +
             | 
| 153 | 
            +
            		# return prayer times for a given date
         | 
| 154 | 
            +
            		def getTimes(date, coords, timezone, dst = 0, format = nil)
         | 
| 155 | 
            +
            			@lat = coords[0]
         | 
| 156 | 
            +
            			@lng = coords[1]
         | 
| 157 | 
            +
            			@elv =  coords.length >2 ? coords[2] : 0
         | 
| 158 | 
            +
             | 
| 159 | 
            +
            			if format != nil
         | 
| 160 | 
            +
            				@@timeFormat = format
         | 
| 161 | 
            +
            			end
         | 
| 162 | 
            +
             | 
| 163 | 
            +
            			if Date.parse(date)
         | 
| 164 | 
            +
            				date = Date.parse(date)
         | 
| 165 | 
            +
            				date = [date.year, date.month, date.day]
         | 
| 166 | 
            +
            			end
         | 
| 167 | 
            +
             | 
| 168 | 
            +
            			@timeZone = timezone + (dst ? 1 : 0)
         | 
| 169 | 
            +
            			@jDate = self.julian(date[0], date[1], date[2]) - @lng / (15 * 24.0)
         | 
| 170 | 
            +
            			return self.computeTimes
         | 
| 171 | 
            +
            		end
         | 
| 172 | 
            +
             | 
| 173 | 
            +
            		# convert float time to the given format (see timeFormats)
         | 
| 174 | 
            +
            		def getFormattedTime(time, format, suffixes = nil)
         | 
| 175 | 
            +
            			
         | 
| 176 | 
            +
            			return self.invalidTime if time.nan?
         | 
| 177 | 
            +
             | 
| 178 | 
            +
            			return time if format == 'Float'
         | 
| 179 | 
            +
             | 
| 180 | 
            +
            			suffixes = @@timeSuffixes if suffixes == nil
         | 
| 181 | 
            +
             | 
| 182 | 
            +
            			time = self.fixhour(time+ 0.5/ 60)  # add 0.5 minutes to round
         | 
| 183 | 
            +
            			hours = time.floor
         | 
| 184 | 
            +
             | 
| 185 | 
            +
            			minutes = ((time - hours)* 60).floor
         | 
| 186 | 
            +
            			suffix = format == '12h' ? suffixes[ hours < 12 ? 0 : 1 ]  : ''
         | 
| 187 | 
            +
            			# formattedTime = "%02d:%02d" % (hours, minutes) if format == "24h" else "%d:%02d" % ((hours+11)%12+1, minutes)
         | 
| 188 | 
            +
            			formattedTime = "#{hours}:#{minutes}"
         | 
| 189 | 
            +
            			return formattedTime + suffix
         | 
| 190 | 
            +
             | 
| 191 | 
            +
            		end
         | 
| 192 | 
            +
             | 
| 193 | 
            +
            		#---------------------- Calculation Functions -----------------------
         | 
| 194 | 
            +
             | 
| 195 | 
            +
            		# compute mid-day time
         | 
| 196 | 
            +
            		def midDay(time)
         | 
| 197 | 
            +
            			eqt = self.sunPosition(@jDate + time)[1]
         | 
| 198 | 
            +
            			return self.fixhour(12 - eqt)
         | 
| 199 | 
            +
            		end
         | 
| 200 | 
            +
             | 
| 201 | 
            +
            		# compute the time at which sun reaches a specific angle below horizon
         | 
| 202 | 
            +
            		def sunAngleTime(angle, time, direction = nil)
         | 
| 203 | 
            +
            			angle
         | 
| 204 | 
            +
            			time
         | 
| 205 | 
            +
            			begin
         | 
| 206 | 
            +
            				decl = self.sunPosition(@jDate + time)[0]
         | 
| 207 | 
            +
            				noon = self.midDay(time)
         | 
| 208 | 
            +
            				t = 1/15.0* self.arccos((-self.sin(angle)- self.sin(decl)* self.sin(@lat))/ (self.cos(decl)* self.cos(@lat)))
         | 
| 209 | 
            +
            					
         | 
| 210 | 
            +
            				return noon + (direction == 'ccw' ? -t  : t)
         | 
| 211 | 
            +
            			rescue 
         | 
| 212 | 
            +
            				return ('nan').to_f
         | 
| 213 | 
            +
            			end
         | 
| 214 | 
            +
            		end
         | 
| 215 | 
            +
             | 
| 216 | 
            +
            		# compute asr time
         | 
| 217 | 
            +
            		def asrTime(factor, time)
         | 
| 218 | 
            +
            			decl = self.sunPosition(@jDate + time)[0]
         | 
| 219 | 
            +
            			angle = -self.arccot(factor + self.tan((@lat - decl).abs))
         | 
| 220 | 
            +
            			return self.sunAngleTime(angle, time)
         | 
| 221 | 
            +
            		end
         | 
| 222 | 
            +
             | 
| 223 | 
            +
            		# compute declination angle of sun and equation of time
         | 
| 224 | 
            +
            		# Ref: http://aa.usno.navy.mil/faq/docs/SunApprox.php
         | 
| 225 | 
            +
            		def sunPosition(jd)
         | 
| 226 | 
            +
            			d = jd - 2451545.0
         | 
| 227 | 
            +
            			g = self.fixangle(357.529 + 0.98560028* d)
         | 
| 228 | 
            +
            			q = self.fixangle(280.459 + 0.98564736* d)
         | 
| 229 | 
            +
            			l = self.fixangle(q + 1.915* self.sin(g) + 0.020* self.sin(2*g))
         | 
| 230 | 
            +
             | 
| 231 | 
            +
            			r = 1.00014 - 0.01671*self.cos(g) - 0.00014*self.cos(2*g)
         | 
| 232 | 
            +
            			e = 23.439 - 0.00000036* d
         | 
| 233 | 
            +
             | 
| 234 | 
            +
            			ra = self.arctan2(self.cos(e)* self.sin(l), self.cos(l))/ 15.0
         | 
| 235 | 
            +
            			eqt = q/15.0 - self.fixhour(ra)
         | 
| 236 | 
            +
            			decl = self.arcsin(self.sin(e)* self.sin(l))
         | 
| 237 | 
            +
             | 
| 238 | 
            +
            			return [decl, eqt]
         | 
| 239 | 
            +
            		end
         | 
| 240 | 
            +
             | 
| 241 | 
            +
            		# convert Gregorian date to Julian day
         | 
| 242 | 
            +
            		# Ref: Astronomical Algorithms by Jean Meeus
         | 
| 243 | 
            +
            		def julian(year, month, day)
         | 
| 244 | 
            +
            			if month <= 2
         | 
| 245 | 
            +
            				year -= 1
         | 
| 246 | 
            +
            				month += 12
         | 
| 247 | 
            +
            			end
         | 
| 248 | 
            +
            			a = (year / 100).floor
         | 
| 249 | 
            +
            			b = 2 - a + (a / 4).floor
         | 
| 250 | 
            +
            			return (365.25 * (year + 4716)).floor + (30.6001 * (month + 1)).floor + day + b - 1524.5
         | 
| 251 | 
            +
            		end
         | 
| 252 | 
            +
             | 
| 253 | 
            +
            		#---------------------- Compute Prayer Times -----------------------
         | 
| 254 | 
            +
             | 
| 255 | 
            +
            		# compute prayer times at given julian date
         | 
| 256 | 
            +
            		def computePrayerTimes(times)
         | 
| 257 | 
            +
            			times   = self.dayPortion(times)
         | 
| 258 | 
            +
            			params  = @@settings
         | 
| 259 | 
            +
             | 
| 260 | 
            +
            			imsak   = self.sunAngleTime(self.eval(params['imsak']), times['imsak'], 'ccw')
         | 
| 261 | 
            +
            			fajr    = self.sunAngleTime(self.eval(params['fajr']), times['fajr'], 'ccw')
         | 
| 262 | 
            +
            			sunrise = self.sunAngleTime(self.riseSetAngle(@elv), times['sunrise'], 'ccw')
         | 
| 263 | 
            +
            			dhuhr   = self.midDay(times['dhuhr'])
         | 
| 264 | 
            +
            			asr     = self.asrTime(self.asrFactor(params['asr']), times['asr'])
         | 
| 265 | 
            +
            			sunset  = self.sunAngleTime(self.riseSetAngle(@elv), times['sunset'])
         | 
| 266 | 
            +
            			maghrib = self.sunAngleTime(self.eval(params['maghrib']), times['maghrib'])
         | 
| 267 | 
            +
            			isha    = self.sunAngleTime(self.eval(params['isha']), times['isha'])
         | 
| 268 | 
            +
            			return {
         | 
| 269 | 
            +
            				'imsak'=> imsak, 'fajr'=> fajr, 'sunrise'=> sunrise, 'dhuhr'=> dhuhr,
         | 
| 270 | 
            +
            				'asr'=> asr, 'sunset'=> sunset, 'maghrib'=> maghrib, 'isha'=> isha
         | 
| 271 | 
            +
            			}
         | 
| 272 | 
            +
            		end
         | 
| 273 | 
            +
             | 
| 274 | 
            +
            		# compute prayer times
         | 
| 275 | 
            +
            		def computeTimes
         | 
| 276 | 
            +
            			times = {
         | 
| 277 | 
            +
            				'imsak'=> 5, 'fajr'=> 5, 'sunrise'=> 6, 'dhuhr'=> 12,
         | 
| 278 | 
            +
            				'asr'=> 13, 'sunset'=> 18, 'maghrib'=> 18, 'isha'=> 18
         | 
| 279 | 
            +
            			}
         | 
| 280 | 
            +
            			# main iterations
         | 
| 281 | 
            +
            			@@numIterations.times do
         | 
| 282 | 
            +
            				times = self.computePrayerTimes(times)
         | 
| 283 | 
            +
            			end
         | 
| 284 | 
            +
            			times = self.adjustTimes(times)
         | 
| 285 | 
            +
            			# add midnight time
         | 
| 286 | 
            +
            			if @@settings['midnight'] == 'Jafari'
         | 
| 287 | 
            +
            				times['midnight'] = times['sunset'] + self.timeDiff(times['sunset'], times['fajr']) / 2
         | 
| 288 | 
            +
            			else
         | 
| 289 | 
            +
            				times['midnight'] = times['sunset'] + self.timeDiff(times['sunset'], times['sunrise']) / 2
         | 
| 290 | 
            +
            			end
         | 
| 291 | 
            +
             | 
| 292 | 
            +
            			times = self.tuneTimes(times)
         | 
| 293 | 
            +
            			return self.modifyFormats(times)
         | 
| 294 | 
            +
            		end
         | 
| 295 | 
            +
             | 
| 296 | 
            +
            		# adjust times in a prayer time array
         | 
| 297 | 
            +
            		def adjustTimes(times)
         | 
| 298 | 
            +
            			params = @@settings
         | 
| 299 | 
            +
            			tzAdjust = @timeZone - @lng / 15.0
         | 
| 300 | 
            +
            			times.each do |t,v|
         | 
| 301 | 
            +
            				times[t] += tzAdjust
         | 
| 302 | 
            +
            			end
         | 
| 303 | 
            +
             | 
| 304 | 
            +
            			if params['highLats'] != nil
         | 
| 305 | 
            +
            				times = self.adjustHighLats(times)
         | 
| 306 | 
            +
            			end
         | 
| 307 | 
            +
             | 
| 308 | 
            +
            			if self.isMin(params['imsak'])
         | 
| 309 | 
            +
            				times['imsak'] = times['fajr'] - self.eval(params['imsak']) / 60.0
         | 
| 310 | 
            +
            			end
         | 
| 311 | 
            +
            			# need to ask about '@@settings
         | 
| 312 | 
            +
            			if self.isMin(params['maghrib'])
         | 
| 313 | 
            +
            				times['maghrib'] = times['sunset'] - self.eval(params['maghrib']) / 60.0
         | 
| 314 | 
            +
            			end
         | 
| 315 | 
            +
             | 
| 316 | 
            +
            			if self.isMin(params['isha'])
         | 
| 317 | 
            +
            				times['isha'] = times['maghrib'] - self.eval(params['isha']) / 60.0
         | 
| 318 | 
            +
            			end
         | 
| 319 | 
            +
            			times['dhuhr'] += self.eval(params['dhuhr']) / 60.0
         | 
| 320 | 
            +
             | 
| 321 | 
            +
            			return times
         | 
| 322 | 
            +
            		end
         | 
| 323 | 
            +
             | 
| 324 | 
            +
            		# get asr shadow factor
         | 
| 325 | 
            +
            		def asrFactor(asrParam)
         | 
| 326 | 
            +
            			methods = {'Standard'=> 1, 'Hanafi'=> 2}
         | 
| 327 | 
            +
            			return methods[asrParam] ? methods[asrParam] : self.eval(asrParam)
         | 
| 328 | 
            +
            		end
         | 
| 329 | 
            +
             | 
| 330 | 
            +
            		# return sun angle for sunset/sunrise
         | 
| 331 | 
            +
            		def riseSetAngle(elevation = 0)
         | 
| 332 | 
            +
            			elevation =  elevation == nil ? 0 : elevation
         | 
| 333 | 
            +
            			return 0.833 + 0.0347 * Math.sqrt(elevation) # an approximation
         | 
| 334 | 
            +
            		end
         | 
| 335 | 
            +
             | 
| 336 | 
            +
            		# apply offset to the times
         | 
| 337 | 
            +
            		def tuneTimes(times)
         | 
| 338 | 
            +
            			times.each do |name, value|
         | 
| 339 | 
            +
            				@@offset
         | 
| 340 | 
            +
            				times[name] += @@offset[name] / 60.0
         | 
| 341 | 
            +
            			end
         | 
| 342 | 
            +
            			return times
         | 
| 343 | 
            +
            		end
         | 
| 344 | 
            +
             | 
| 345 | 
            +
            		# convert times to given time format
         | 
| 346 | 
            +
            		def modifyFormats(times)
         | 
| 347 | 
            +
            			times.each do |name, value|
         | 
| 348 | 
            +
            				times[name] = self.getFormattedTime(times[name], @@timeFormat)
         | 
| 349 | 
            +
            			end
         | 
| 350 | 
            +
            			return times
         | 
| 351 | 
            +
            		end
         | 
| 352 | 
            +
             | 
| 353 | 
            +
            		# adjust times for locations in higher latitudes
         | 
| 354 | 
            +
            		def adjustHighLats(times)
         | 
| 355 | 
            +
            			params = @@settings
         | 
| 356 | 
            +
            			nightTime = self.timeDiff(times['sunset'], times['sunrise']) # sunset to sunrise
         | 
| 357 | 
            +
            			times['imsak'] = self.adjustHLTime(times['imsak'], times['sunrise'], self.eval(params['imsak']), nightTime, 'ccw')
         | 
| 358 | 
            +
            			times['fajr']  = self.adjustHLTime(times['fajr'], times['sunrise'], self.eval(params['fajr']), nightTime, 'ccw')
         | 
| 359 | 
            +
            			times['isha']  = self.adjustHLTime(times['isha'], times['sunset'], self.eval(params['isha']), nightTime)
         | 
| 360 | 
            +
            			times['maghrib'] = self.adjustHLTime(times['maghrib'], times['sunset'], self.eval(params['maghrib']), nightTime)
         | 
| 361 | 
            +
            			return times
         | 
| 362 | 
            +
            		end
         | 
| 363 | 
            +
             | 
| 364 | 
            +
            		# adjust a time for higher latitudes
         | 
| 365 | 
            +
            		def adjustHLTime(time, base, angle, night, direction = nil)
         | 
| 366 | 
            +
            			portion = self.nightPortion(angle, night)
         | 
| 367 | 
            +
            			diff =  direction == 'ccw' ? self.timeDiff(time, base) : self.timeDiff(base, time)
         | 
| 368 | 
            +
            			if time.nan? or diff > portion
         | 
| 369 | 
            +
            				time = base + ( direction == 'ccw' ? -portion : portion)
         | 
| 370 | 
            +
            			end
         | 
| 371 | 
            +
            			return time
         | 
| 372 | 
            +
            		end
         | 
| 373 | 
            +
             | 
| 374 | 
            +
            		# the night portion used for adjusting times in higher latitudes
         | 
| 375 | 
            +
            		def nightPortion(angle, night)
         | 
| 376 | 
            +
            			method = @@settings['highLats']
         | 
| 377 | 
            +
            			portion = 1/2.0  # midnight
         | 
| 378 | 
            +
            			if method == 'AngleBased'
         | 
| 379 | 
            +
            				portion = 1/60.0 * angle
         | 
| 380 | 
            +
            			end
         | 
| 381 | 
            +
            			if method == 'OneSeventh'
         | 
| 382 | 
            +
            				portion = 1/7.0
         | 
| 383 | 
            +
            			end
         | 
| 384 | 
            +
            			return portion * night
         | 
| 385 | 
            +
            		end
         | 
| 386 | 
            +
             | 
| 387 | 
            +
            		# convert hours to day portions
         | 
| 388 | 
            +
            		def dayPortion(times)
         | 
| 389 | 
            +
            			times.each do |key, value|
         | 
| 390 | 
            +
            				times[key] = value /= 24.0
         | 
| 391 | 
            +
            			end
         | 
| 392 | 
            +
            			return times
         | 
| 393 | 
            +
            		end
         | 
| 394 | 
            +
             | 
| 395 | 
            +
             | 
| 396 | 
            +
            		#---------------------- Misc Functions -----------------------
         | 
| 397 | 
            +
             | 
| 398 | 
            +
            		# compute the difference between two times
         | 
| 399 | 
            +
            		def timeDiff(time1, time2)
         | 
| 400 | 
            +
            			return self.fixhour(time2- time1)
         | 
| 401 | 
            +
            		end
         | 
| 402 | 
            +
             | 
| 403 | 
            +
            		# convert given string into a number
         | 
| 404 | 
            +
            		def eval(st)
         | 
| 405 | 
            +
            			val = st.to_s.split('[^0-9.+-]')[0]
         | 
| 406 | 
            +
            			return   val ? val.to_f : 0
         | 
| 407 | 
            +
            		end
         | 
| 408 | 
            +
             | 
| 409 | 
            +
            		# detect if input contains 'min'
         | 
| 410 | 
            +
            		def isMin(arg)
         | 
| 411 | 
            +
            			return arg.to_s.include?('min')
         | 
| 412 | 
            +
            		end
         | 
| 413 | 
            +
             | 
| 414 | 
            +
             | 
| 415 | 
            +
            		#----------------- Degree-Based Math Functions -------------------
         | 
| 416 | 
            +
             | 
| 417 | 
            +
            		def sin(d) return Math.sin((d) * Math::PI / 180); end
         | 
| 418 | 
            +
            		def cos(d) return Math.cos((d) * Math::PI / 180); end
         | 
| 419 | 
            +
            		def tan(d) return Math.tan((d) * Math::PI / 180); end
         | 
| 420 | 
            +
             | 
| 421 | 
            +
            		def arcsin(x) return ((Math.asin(x)* 180.0) / Math::PI); end
         | 
| 422 | 
            +
            		def arccos(x) return ((Math.acos(x)* 180.0) / Math::PI); end
         | 
| 423 | 
            +
            		def arctan(x) return ((Math.atan(x)* 180.0) / Math::PI); end
         | 
| 424 | 
            +
             | 
| 425 | 
            +
            		def arccot(x) return ((Math.atan(1.0/x)* 180.0) / Math::PI); end
         | 
| 426 | 
            +
            		def arctan2(y, x) return ((Math.atan2(y, x)* 180.0) / Math::PI); end
         | 
| 427 | 
            +
             | 
| 428 | 
            +
            		def fixangle(angle) return self.fix(angle, 360.0); end
         | 
| 429 | 
            +
            		def fixhour(hour) return self.fix(hour, 24.0); end
         | 
| 430 | 
            +
             | 
| 431 | 
            +
            		def fix(a, mode)
         | 
| 432 | 
            +
            			if a.nan?
         | 
| 433 | 
            +
            				return a
         | 
| 434 | 
            +
            			end
         | 
| 435 | 
            +
            			a = a - mode * ((a / mode).floor)
         | 
| 436 | 
            +
            			return  a < 0 ? a + mode : a
         | 
| 437 | 
            +
            		end
         | 
| 438 | 
            +
             | 
| 439 | 
            +
             | 
| 440 | 
            +
             | 
| 441 | 
            +
            	end
         | 
| 442 | 
            +
            end
         | 
    
        data/prayertimes.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 'prayertimes/version'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "prayertimes"
         | 
| 8 | 
            +
              spec.version       = Prayertimes::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Mohamed El Mahallawy"]
         | 
| 10 | 
            +
              spec.email         = ["mmahalwy@gmail.com"]
         | 
| 11 | 
            +
              spec.summary       = %q{ Gem used for calculating prayer times.}
         | 
| 12 | 
            +
              spec.description   = %q{Gem used for calculating prayer times.}
         | 
| 13 | 
            +
              spec.homepage      = ""
         | 
| 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_development_dependency "bundler", "~> 1.7"
         | 
| 22 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 23 | 
            +
              spec.add_development_dependency "rspec"
         | 
| 24 | 
            +
            end
         | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | @@ -0,0 +1 @@ | |
| 1 | 
            +
            require 'prayertimes'
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,98 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: prayertimes
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 1.0.0
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Mohamed El Mahallawy
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2014-09-08 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.7'
         | 
| 20 | 
            +
              type: :development
         | 
| 21 | 
            +
              prerelease: false
         | 
| 22 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 | 
            +
                requirements:
         | 
| 24 | 
            +
                - - "~>"
         | 
| 25 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 26 | 
            +
                    version: '1.7'
         | 
| 27 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 28 | 
            +
              name: rake
         | 
| 29 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 | 
            +
                requirements:
         | 
| 31 | 
            +
                - - "~>"
         | 
| 32 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            +
                    version: '10.0'
         | 
| 34 | 
            +
              type: :development
         | 
| 35 | 
            +
              prerelease: false
         | 
| 36 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
                requirements:
         | 
| 38 | 
            +
                - - "~>"
         | 
| 39 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                    version: '10.0'
         | 
| 41 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 42 | 
            +
              name: rspec
         | 
| 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: Gem used for calculating prayer times.
         | 
| 56 | 
            +
            email:
         | 
| 57 | 
            +
            - mmahalwy@gmail.com
         | 
| 58 | 
            +
            executables: []
         | 
| 59 | 
            +
            extensions: []
         | 
| 60 | 
            +
            extra_rdoc_files: []
         | 
| 61 | 
            +
            files:
         | 
| 62 | 
            +
            - ".gitignore"
         | 
| 63 | 
            +
            - Gemfile
         | 
| 64 | 
            +
            - LICENSE.txt
         | 
| 65 | 
            +
            - README.md
         | 
| 66 | 
            +
            - Rakefile
         | 
| 67 | 
            +
            - lib/prayertimes.rb
         | 
| 68 | 
            +
            - lib/prayertimes/version.rb
         | 
| 69 | 
            +
            - prayertimes.gemspec
         | 
| 70 | 
            +
            - spec/prayertimes_spec.rb
         | 
| 71 | 
            +
            - spec/spec_helper.rb
         | 
| 72 | 
            +
            homepage: ''
         | 
| 73 | 
            +
            licenses:
         | 
| 74 | 
            +
            - MIT
         | 
| 75 | 
            +
            metadata: {}
         | 
| 76 | 
            +
            post_install_message: 
         | 
| 77 | 
            +
            rdoc_options: []
         | 
| 78 | 
            +
            require_paths:
         | 
| 79 | 
            +
            - lib
         | 
| 80 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 81 | 
            +
              requirements:
         | 
| 82 | 
            +
              - - ">="
         | 
| 83 | 
            +
                - !ruby/object:Gem::Version
         | 
| 84 | 
            +
                  version: '0'
         | 
| 85 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
              requirements:
         | 
| 87 | 
            +
              - - ">="
         | 
| 88 | 
            +
                - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                  version: '0'
         | 
| 90 | 
            +
            requirements: []
         | 
| 91 | 
            +
            rubyforge_project: 
         | 
| 92 | 
            +
            rubygems_version: 2.2.2
         | 
| 93 | 
            +
            signing_key: 
         | 
| 94 | 
            +
            specification_version: 4
         | 
| 95 | 
            +
            summary: Gem used for calculating prayer times.
         | 
| 96 | 
            +
            test_files:
         | 
| 97 | 
            +
            - spec/prayertimes_spec.rb
         | 
| 98 | 
            +
            - spec/spec_helper.rb
         |