solar 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.
data/Gemfile CHANGED
@@ -1,7 +1,6 @@
1
1
  source "http://rubygems.org"
2
- # Add dependencies required to use your gem here.
3
- # Example:
4
- # gem "activesupport", ">= 2.3.5"
2
+
3
+ gem 'activesupport'
5
4
 
6
5
  # Add dependencies to develop your gem here.
7
6
  # Include everything needed to run rake, tests, features, etc.
@@ -27,6 +27,7 @@ PLATFORMS
27
27
  ruby
28
28
 
29
29
  DEPENDENCIES
30
+ activesupport
30
31
  bundler (~> 1)
31
32
  jeweler (~> 1.8.4)
32
33
  rdoc (~> 3.12)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,3 +1,6 @@
1
+ require 'active_support'
2
+ require 'active_support/time'
3
+
1
4
  # Calculation of solar position, rise & set times for a given position & time.
2
5
  # Algorithms are taken from Jean Meeus, Astronomical Algorithms
3
6
  # Some code & ideas taken from John P. Power's astro-algo: http://astro-algo.rubyforge.org/astro-algo/
@@ -20,16 +23,40 @@ module Solar
20
23
  # * :day_zenith zenith for the san at sunrise and sun set.
21
24
  # Default: :official (sun aparently under the horizon, tangent to it)
22
25
  # These parameters can be assigned zenith values in degrees of the symbols:
23
- # :official, :civil, :nautical or :astronomical.
26
+ # :official, :civil, :nautical or :astronomical.
27
+ # Simple day night result (returning :day or :night) can be requested
28
+ # by setting :simple=>true (which usses the official day definition)
29
+ # or by setting a :zenith parameter to the fine the kind of day-night
30
+ # distinction.
31
+ # By passing :detailed=>true, the result will be one of:
32
+ # :night, :astronomical_twilight, :nautical_twilight, :civil_twilight, :day
24
33
  def day_or_night(t, longitude, latitude, options={})
25
- if options[:zenith]
26
- twilight_altitude = day_altitude = altitude_from_options(options)
34
+ h, az = position(t, longitude, latitude)
35
+ options = {:zenith=>:official} if options[:simple]
36
+ if options[:detailed]
37
+ if h<Solar::ALTITUDES[:astronomical]
38
+ :night
39
+ elsif h<Solar::ALTITUDES[:nautical]
40
+ :astronomical_twilight
41
+ elsif h<Solar::ALTITUDES[:civil]
42
+ :nautical_twilight
43
+ elsif h<Solar::ALTITUDES[:official]
44
+ :civil_twilight
45
+ else
46
+ :day
47
+ end
27
48
  else
28
- twilight_altitude = altitude_from_options(:zenith => options[:twilight_zenith] || :civil)
29
- day_altitude = altitude_from_options(:zenith => options[:day_zenith] || :official)
49
+ # Determined :night / :twilight / :day state;
50
+ # twilight/day definition can be changed with options :zenith or :twilight_zenith, :day_zenith
51
+ if options[:zenith]
52
+ # only :day / :night distinction as defined by :zenith
53
+ twilight_altitude = day_altitude = altitude_from_options(options)
54
+ else
55
+ twilight_altitude = altitude_from_options(:zenith => options[:twilight_zenith] || :civil)
56
+ day_altitude = altitude_from_options(:zenith => options[:day_zenith] || :official)
57
+ end
58
+ (h > day_altitude) ? :day : (h <= twilight_altitude) ? :night : :twilight
30
59
  end
31
- al,az = position(t, longitude, latitude)
32
- (al > day_altitude) ? :day : (al <= twilight_altitude) ? :night : :twilight
33
60
  end
34
61
 
35
62
  # Sun horizontal coordinates (relative position) in degrees:
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "solar"
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Javier Goizueta"]
12
- s.date = "2012-10-07"
12
+ s.date = "2012-10-08"
13
13
  s.description = "# Calculation of solar position, rise & set times for a given position & time."
14
14
  s.email = "jgoizueta@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -39,17 +39,20 @@ Gem::Specification.new do |s|
39
39
  s.specification_version = 3
40
40
 
41
41
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
42
43
  s.add_development_dependency(%q<shoulda>, [">= 0"])
43
44
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
44
45
  s.add_development_dependency(%q<bundler>, ["~> 1"])
45
46
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
46
47
  else
48
+ s.add_dependency(%q<activesupport>, [">= 0"])
47
49
  s.add_dependency(%q<shoulda>, [">= 0"])
48
50
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
49
51
  s.add_dependency(%q<bundler>, ["~> 1"])
50
52
  s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
51
53
  end
52
54
  else
55
+ s.add_dependency(%q<activesupport>, [">= 0"])
53
56
  s.add_dependency(%q<shoulda>, [">= 0"])
54
57
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
55
58
  s.add_dependency(%q<bundler>, ["~> 1"])
@@ -1,3 +1,29 @@
1
1
  require 'helper'
2
2
 
3
- # TODO: write tests!!
3
+ class TestSolar < Test::Unit::TestCase
4
+
5
+ should "calculate transits for the required date" do
6
+ d = Date.new(2012,10,7)
7
+ for lon in -360..360
8
+ for lat in -5..5
9
+ lat *= 10
10
+ r,trans,s = Solar.passages(d, lon, lat)
11
+ assert_equal d, trans.utc.to_date, "longitude: #{lon} latitude: #{lat}"
12
+ end
13
+ end
14
+ end
15
+
16
+ should "determine if it's day or night" do
17
+ assert_equal :day, Solar.day_or_night(Time.utc(2012,10,7,9,0,0), 0, 42)
18
+ assert_equal :day, Solar.day_or_night(Time.utc(2012,10,7,9,0,0), 0, 42, :detailed=>true)
19
+ assert_equal :day, Solar.day_or_night(Time.utc(2012,10,7,9,0,0), 0, 42, :simple=>true)
20
+ assert_equal :night, Solar.day_or_night(Time.utc(2012,10,7,21,0,0), 0, 42)
21
+ assert_equal :night, Solar.day_or_night(Time.utc(2012,10,7,21,0,0), 0, 42, :detailed=>true)
22
+ assert_equal :night, Solar.day_or_night(Time.utc(2012,10,7,21,0,0), 0, 42, :simple=>true)
23
+ assert_equal :night, Solar.day_or_night(Time.utc(2012,12,7,9,0,0), 0, 89)
24
+ assert_equal :twilight, Solar.day_or_night(Time.utc(2012,10,7,9,0,0), 0, 89)
25
+ assert_equal :day, Solar.day_or_night(Time.utc(2012,12,7,9,0,0), 0, -89)
26
+ assert_equal :day, Solar.day_or_night(Time.utc(2012,10,7,9,0,0), 0, -89)
27
+ end
28
+
29
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-07 00:00:00.000000000 Z
12
+ date: 2012-10-08 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: shoulda
16
32
  requirement: !ruby/object:Gem::Requirement
@@ -110,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
126
  version: '0'
111
127
  segments:
112
128
  - 0
113
- hash: -1434105629411668525
129
+ hash: -3223580498560321012
114
130
  required_rubygems_version: !ruby/object:Gem::Requirement
115
131
  none: false
116
132
  requirements: