RubySunrise 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e36babfce42eb42418ae75fb536897c8e72a5797
4
- data.tar.gz: f5f4f3ff61c529a41017d2a64bc0e442364bdb52
2
+ SHA256:
3
+ metadata.gz: 2925333b6dad5cdec7f8b89883b3e0e94e2511aa928924ab7221dcf330ee44d6
4
+ data.tar.gz: 8c7eb64768f429d7e61561e8edf6f900329b87eb622a5d467370dcbee0c325ad
5
5
  SHA512:
6
- metadata.gz: 7d44ac4e648cc9537442b7a5af5ec585806e0bf718daeb94838fa0612daa4097fac6d622420a14a6ac809c9d15a431475344b76f18dfea057eb30b1611c38ce0
7
- data.tar.gz: 7aabe8fa9fe349867a1909731b04a1c036addcba2fed6b5821ff4265a314fa1b7b68f194f47b205294e61b5bc3c8c248f9fd2b447684187c67b7c506a9f07698
6
+ metadata.gz: 6389404d2377c5dd2bbff2bc05deb5344d777d0d1b09edae4afcd8545f7f8eca640a09e40e00ffe55a83084d5d8b161c74348d35f7a54cd8dd887f0894bf7c57
7
+ data.tar.gz: a3a3fd2991867b29b49babec552b261fe63dffa1a9ef3773b823392dcf32189ca64c2a23ff68b00cce2a6b48d90770e7fd4ab8a325cc8a0649117a0bdc11ee1c
@@ -4,10 +4,6 @@ require 'tzinfo'
4
4
 
5
5
  class SolarEventCalculator
6
6
 
7
- @date
8
- @latitude
9
- @longitude
10
-
11
7
  def initialize(date, latitude, longitude)
12
8
  @date = date
13
9
  @latitude = latitude
@@ -15,64 +11,64 @@ class SolarEventCalculator
15
11
  end
16
12
 
17
13
  def compute_lnghour
18
- lngHour = @longitude / BigDecimal.new("15")
14
+ lngHour = @longitude / BigDecimal("15")
19
15
  lngHour.round(4)
20
16
  end
21
17
 
22
18
  def compute_longitude_hour(isSunrise)
23
- minuend = (isSunrise) ? BigDecimal.new("6") : BigDecimal.new("18")
24
- longHour = @date.yday + ((minuend - compute_lnghour) / BigDecimal.new("24"))
19
+ minuend = (isSunrise) ? BigDecimal("6") : BigDecimal("18")
20
+ longHour = @date.yday + ((minuend - compute_lnghour) / BigDecimal("24"))
25
21
  longHour.round(4)
26
22
  end
27
23
 
28
24
  def compute_sun_mean_anomaly(longHour)
29
- constant = BigDecimal.new("0.9856")
30
- ((longHour * constant) - BigDecimal.new("3.289")).round(4)
25
+ constant = BigDecimal("0.9856")
26
+ ((longHour * constant) - BigDecimal("3.289")).round(4)
31
27
  end
32
28
 
33
29
  def compute_sun_true_longitude(meanAnomaly)
34
30
  mAsRads = degrees_as_rads(meanAnomaly)
35
- sinM = BigDecimal.new(Math.sin(mAsRads.to_f).to_s)
36
- sinTwoM = BigDecimal.new(Math.sin((2 * mAsRads).to_f).to_s)
37
- firstParens = BigDecimal.new("1.916") * sinM
38
- secondParens = BigDecimal.new("0.020") * sinTwoM
39
- trueLong = meanAnomaly + firstParens + secondParens + BigDecimal.new("282.634")
31
+ sinM = BigDecimal(Math.sin(mAsRads.to_f).to_s)
32
+ sinTwoM = BigDecimal(Math.sin((2 * mAsRads).to_f).to_s)
33
+ firstParens = BigDecimal("1.916") * sinM
34
+ secondParens = BigDecimal("0.020") * sinTwoM
35
+ trueLong = meanAnomaly + firstParens + secondParens + BigDecimal("282.634")
40
36
  trueLong = put_in_range(trueLong, 0, 360, 360)
41
37
  trueLong.round(4)
42
38
  end
43
39
 
44
40
  def compute_right_ascension(sunTrueLong)
45
- tanL = BigDecimal.new(Math.tan(degrees_as_rads(sunTrueLong).to_f).to_s)
46
- ra = rads_as_degrees(BigDecimal.new(Math.atan(BigDecimal.new("0.91764") * tanL).to_s))
41
+ tanL = BigDecimal(Math.tan(degrees_as_rads(sunTrueLong).to_f).to_s)
42
+ ra = rads_as_degrees(BigDecimal(Math.atan(BigDecimal("0.91764") * tanL).to_s))
47
43
 
48
44
  ra = put_in_range(ra, 0, 360, 360)
49
45
  ra.round(4)
50
46
  end
51
47
 
52
48
  def put_ra_in_correct_quadrant(sunTrueLong)
53
- lQuadrant = BigDecimal.new("90") * (sunTrueLong / BigDecimal.new("90")).floor
54
- raQuadrant = BigDecimal.new("90") * (compute_right_ascension(sunTrueLong) / BigDecimal.new("90")).floor
49
+ lQuadrant = BigDecimal("90") * (sunTrueLong / BigDecimal("90")).floor
50
+ raQuadrant = BigDecimal("90") * (compute_right_ascension(sunTrueLong) / BigDecimal("90")).floor
55
51
 
56
52
  ra = compute_right_ascension(sunTrueLong) + (lQuadrant - raQuadrant)
57
- ra = ra / BigDecimal.new("15")
53
+ ra = ra / BigDecimal("15")
58
54
  ra.round(4)
59
55
  end
60
56
 
61
57
  def compute_sin_sun_declination(sunTrueLong)
62
- sinL = BigDecimal.new(Math.sin(degrees_as_rads(sunTrueLong).to_f).to_s)
63
- sinDec = sinL * BigDecimal.new("0.39782")
58
+ sinL = BigDecimal(Math.sin(degrees_as_rads(sunTrueLong).to_f).to_s)
59
+ sinDec = sinL * BigDecimal("0.39782")
64
60
  sinDec.round(4)
65
61
  end
66
62
 
67
63
  def compute_cosine_sun_declination(sinSunDeclination)
68
- cosDec = BigDecimal.new(Math.cos(Math.asin(sinSunDeclination)).to_s)
64
+ cosDec = BigDecimal(Math.cos(Math.asin(sinSunDeclination)).to_s)
69
65
  cosDec.round(4)
70
66
  end
71
67
 
72
68
  def compute_cosine_sun_local_hour(sunTrueLong, zenith)
73
- cosZenith = BigDecimal.new(Math.cos(degrees_as_rads(BigDecimal.new(zenith.to_s))).to_s)
74
- sinLatitude = BigDecimal.new(Math.sin(degrees_as_rads(@latitude)).to_s)
75
- cosLatitude = BigDecimal.new(Math.cos(degrees_as_rads(@latitude)).to_s)
69
+ cosZenith = BigDecimal(Math.cos(degrees_as_rads(BigDecimal(zenith.to_s))).to_s)
70
+ sinLatitude = BigDecimal(Math.sin(degrees_as_rads(@latitude)).to_s)
71
+ cosLatitude = BigDecimal(Math.cos(degrees_as_rads(@latitude)).to_s)
76
72
 
77
73
  sinSunDeclination = compute_sin_sun_declination(sunTrueLong)
78
74
  top = cosZenith - (sinSunDeclination * sinLatitude)
@@ -83,11 +79,11 @@ class SolarEventCalculator
83
79
  end
84
80
 
85
81
  def compute_local_hour_angle(cosSunLocalHour, isSunrise)
86
- acosH = BigDecimal.new(Math.acos(cosSunLocalHour).to_s)
82
+ acosH = BigDecimal(Math.acos(cosSunLocalHour).to_s)
87
83
  acosHDegrees = rads_as_degrees(acosH)
88
84
 
89
- localHourAngle = (isSunrise) ? BigDecimal.new("360") - acosHDegrees : acosHDegrees
90
- localHourAngle = localHourAngle / BigDecimal.new("15")
85
+ localHourAngle = (isSunrise) ? BigDecimal("360") - acosHDegrees : acosHDegrees
86
+ localHourAngle = localHourAngle / BigDecimal("15")
91
87
  localHourAngle.round(4)
92
88
  end
93
89
 
@@ -95,8 +91,8 @@ class SolarEventCalculator
95
91
  h = sunLocalHour
96
92
  ra = put_ra_in_correct_quadrant(sunTrueLong)
97
93
 
98
- parens = BigDecimal.new("0.06571") * t
99
- time = h + ra - parens - BigDecimal.new("6.622")
94
+ parens = BigDecimal("0.06571") * t
95
+ time = h + ra - parens - BigDecimal("6.622")
100
96
 
101
97
  utcTime = time - longHour
102
98
  utcTime = put_in_range(utcTime, 0, 24, 24)
@@ -111,7 +107,7 @@ class SolarEventCalculator
111
107
  sunTrueLong = compute_sun_true_longitude(meanAnomaly)
112
108
  cosineSunLocalHour = compute_cosine_sun_local_hour(sunTrueLong, zenith)
113
109
 
114
- if(cosineSunLocalHour > BigDecimal.new("1") || cosineSunLocalHour < BigDecimal.new("-1"))
110
+ if(cosineSunLocalHour > BigDecimal("1") || cosineSunLocalHour < BigDecimal("-1"))
115
111
  return nil
116
112
  end
117
113
 
@@ -119,7 +115,7 @@ class SolarEventCalculator
119
115
  localMeanTime = compute_local_mean_time(sunTrueLong, longHour, eventLongHour, sunLocalHour)
120
116
 
121
117
  timeParts = localMeanTime.to_f.to_s.split('.')
122
- mins = BigDecimal.new("." + timeParts[1]) * BigDecimal.new("60")
118
+ mins = BigDecimal("." + timeParts[1]) * BigDecimal("60")
123
119
  mins = mins.truncate()
124
120
  mins = pad_minutes(mins.to_i)
125
121
  hours = timeParts[0]
@@ -235,13 +231,14 @@ class SolarEventCalculator
235
231
 
236
232
  def degrees_as_rads(degrees)
237
233
  pi = BigDecimal(Math::PI.to_s)
238
- radian = pi / BigDecimal.new("180")
234
+ radian = pi / BigDecimal("180")
239
235
  degrees * radian
240
236
  end
241
237
 
242
238
  def rads_as_degrees(radians)
243
239
  pi = BigDecimal(Math::PI.to_s)
244
- degree = BigDecimal.new("180") / pi
240
+ degree = BigDecimal("180") / pi
245
241
  radians * degree
246
242
  end
243
+
247
244
  end
@@ -1,6 +1,6 @@
1
1
  spec = Gem::Specification.new do | s |
2
2
  s.name = "RubySunrise"
3
- s.version = "0.3.1"
3
+ s.version = "0.3.2"
4
4
  s.author = "Mike Reedell / LuckyCatLabs"
5
5
  s.email = "mike@reedell.com"
6
6
  s.homepage = "http://www.mikereedell.com"
@@ -10,4 +10,4 @@ spec = Gem::Specification.new do | s |
10
10
  s.test_files = Dir.glob("{test}/**/*test.rb")
11
11
  s.has_rdoc = false
12
12
  s.add_runtime_dependency "tzinfo"
13
- end
13
+ end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RubySunrise
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Reedell / LuckyCatLabs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tzinfo
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  description:
@@ -30,8 +30,8 @@ executables: []
30
30
  extensions: []
31
31
  extra_rdoc_files: []
32
32
  files:
33
- - rubysunrise.gemspec
34
33
  - lib/solareventcalculator.rb
34
+ - rubysunrise.gemspec
35
35
  - test/bulkdatatest.rb
36
36
  - test/sunrisetest.rb
37
37
  - test/sunsettest.rb
@@ -44,17 +44,16 @@ require_paths:
44
44
  - lib
45
45
  required_ruby_version: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - '>='
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
49
  version: '0'
50
50
  required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  requirements: []
56
- rubyforge_project:
57
- rubygems_version: 2.0.14
56
+ rubygems_version: 3.0.3
58
57
  signing_key:
59
58
  specification_version: 4
60
59
  summary: Calculate the sunrise/sunset given lat/long coordinates and the date. Computes