gstatsat 0.0.1 → 0.0.2

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 (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gstatsat.rb +23 -15
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 57ba5bf813ce4ba2b8a7fc273004836740b92919
4
- data.tar.gz: 37f8c3963bde37d7a2df65b48d1ee4659ace123c
3
+ metadata.gz: e11b22e10d7b531331b0290b2977a003ad145c5b
4
+ data.tar.gz: 8cabcd3a6a28754d8eb087cada35fe09ad39d629
5
5
  SHA512:
6
- metadata.gz: fdb3907c8267a5eddc537e3a9f6b5f443863c71294a47b5c7a587d817d851068bc87770d6f280f2a280e08b6a75b8e788ddaab8ef351e568e526b7f9e8c75a7e
7
- data.tar.gz: fd576aa38e15a65d769bb9432776c77c4ee7eb79c262578d267b2d3fc5e4b87986bbe5548dbba7d4e874eadef3c7ce1dd70859aa2251d23beefed3974dd45590
6
+ metadata.gz: 9fd35ff06641e175885c8fae13ccd3ada9745b42d33a4d73860812856cf02a9d24530e5fd746cdc345bc02efb403982f1b8d1f52a5f496ed7cc4ec77676fa0ba
7
+ data.tar.gz: 9e52d6a4b02f5e4f08e53ab392a8dd8b7a359ff69266d41bb30f748d209b584499bf490881ae8586f012ab4bad72d8180c0c57501ee18db713cffe0792cf5632
data/lib/gstatsat.rb CHANGED
@@ -6,11 +6,12 @@ module Gstatsat
6
6
  @longitude = params.fetch(:longitude)
7
7
  end
8
8
 
9
- def validate(params)
10
- longitude = params.fetch(:longitude)
11
- raise KeyError, 'longitude is not numeric' unless longitude.is_a? Numeric
12
- raise KeyError, 'invalid longitude value' unless longitude >= -180 && longitude <= 180
13
- end
9
+ private
10
+ def validate(params)
11
+ longitude = params.fetch(:longitude)
12
+ raise KeyError, 'longitude is not numeric' unless longitude.is_a? Numeric
13
+ raise KeyError, 'invalid longitude value' unless longitude >= -180 && longitude <= 180
14
+ end
14
15
  end
15
16
 
16
17
  class BaseStation
@@ -21,19 +22,21 @@ module Gstatsat
21
22
  @longitude = params.fetch(:longitude)
22
23
  end
23
24
 
24
- def validate(params)
25
- longitude = params.fetch(:longitude)
26
- latitude = params.fetch(:latitude)
27
- raise KeyError, 'longitude is not numeric' unless longitude.is_a? Numeric
28
- raise KeyError, 'latitude is not numeric' unless latitude.is_a? Numeric
29
- raise KeyError, 'invalid longitude value' unless longitude >= -180 && longitude <= 180
30
- raise KeyError, 'invalid latitude value' unless latitude >= -90 && latitude <= 90
31
- end
25
+ private
26
+ def validate(params)
27
+ longitude = params.fetch(:longitude)
28
+ latitude = params.fetch(:latitude)
29
+ raise KeyError, 'longitude is not numeric' unless longitude.is_a? Numeric
30
+ raise KeyError, 'latitude is not numeric' unless latitude.is_a? Numeric
31
+ raise KeyError, 'invalid longitude value' unless longitude >= -180 && longitude <= 180
32
+ raise KeyError, 'invalid latitude value' unless latitude >= -90 && latitude <= 90
33
+ end
32
34
  end
33
35
 
34
36
  class SatelliteBearing
35
37
  attr_accessor :azimuth, :elevation
36
38
  def initialize(params = {})
39
+ validate(params)
37
40
  @satellite = params.fetch(:satellite)
38
41
  @base_station = params.fetch(:base_station)
39
42
  calculate_bearing
@@ -52,8 +55,8 @@ module Gstatsat
52
55
  sigma = earths_radius.to_f / ( earths_radius + satellite_height )
53
56
  beta = Math.acos(Math.cos(base_station_latitude_rads) * Math.cos(azimuthal_angle_rads))
54
57
 
55
- @elevation = to_degrees(Math.atan(( Math.cos(beta) - sigma) / Math.sin(beta))).round(1)
56
- @azimuth = to_degrees(Math::PI + Math::atan(Math::tan(azimuthal_angle_rads)/Math::sin(base_station_latitude_rads))).round(1)
58
+ @elevation = to_degrees(Math.atan((Math.cos(beta) - sigma) / Math.sin(beta))).round(1)
59
+ @azimuth = to_degrees(Math::PI + Math::atan(Math::tan(azimuthal_angle_rads) / Math::sin(base_station_latitude_rads))).round(1)
57
60
  end
58
61
 
59
62
  def to_radians(degrees)
@@ -63,5 +66,10 @@ module Gstatsat
63
66
  def to_degrees(radians)
64
67
  radians * 180 / Math::PI
65
68
  end
69
+
70
+ def validate(params)
71
+ raise KeyError, 'satellite is not Gstatsat::Satellite class' unless params.fetch(:satellite).is_a? Gstatsat::Satellite
72
+ raise KeyError, 'base_station is not Gstatsat::BaseStation class' unless params.fetch(:base_station).is_a? Gstatsat::BaseStation
73
+ end
66
74
  end
67
75
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gstatsat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Clarke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-12 00:00:00.000000000 Z
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple gem for calculating bearings of geostationary satellites
14
14
  email: greg@gho.st
@@ -37,7 +37,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  version: '0'
38
38
  requirements: []
39
39
  rubyforge_project:
40
- rubygems_version: 2.5.1
40
+ rubygems_version: 2.6.10
41
41
  signing_key:
42
42
  specification_version: 4
43
43
  summary: Calculate bearings of geostationary satellites