solunar 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/solunar.rb +67 -52
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 304e7335299f7bee983f4114b1b46448be50a6ee
4
- data.tar.gz: e7898a6aa64ed2960841b60fae096897397ae4cd
3
+ metadata.gz: 2f066032447311375e4901e1108397e9f8aa3947
4
+ data.tar.gz: f17b7a85aff92490c0ca424a07080dba9cd7e69a
5
5
  SHA512:
6
- metadata.gz: 6f6700d9d123996b9f29c79c059f142232aa1e8155b31e486d7b226bb4791493f24091639188a66b41283b9f06c1a6afebc0124df323975ab7013121b387a306
7
- data.tar.gz: a6929163b44e40cafc67a94c3de850fc7b1f4d6d0e1d3d37bbe71f010de2f15df8cc3002c02f41cf09c0f49e6da1ea65a23598936500dda40c1c71a8c1dc469d
6
+ metadata.gz: f2cbd6dafc7a45e4c65035d214f7895221f06b668473b06c1a005ff9fbe96f2784e6a07d7c7ba7798c7fe696445d3dcc954c3cdbcbcbd3bb344b5587fe1e4a0b
7
+ data.tar.gz: fcd5d2724403176670dedb3074ab3c8644eb6a5f72d4c73e59b4ad990d68906d8352112515a51d1ab5822b004cd1e5a00a9017f91f2810ded93f18b40a2f7d2b
@@ -1,9 +1,10 @@
1
1
  class Solunar
2
+ require 'time'
2
3
 
3
4
  NAME = "solunar"
4
- VERSION = '0.0.10'
5
+ VERSION = '0.0.11'
5
6
  def version
6
- "0.0.10"
7
+ "0.0.11"
7
8
  end
8
9
 
9
10
  def test
@@ -20,37 +21,78 @@ class Solunar
20
21
  res.split(";").each do |line|
21
22
  next unless line.split(",").length > 7
22
23
  segments = line.split(",")
24
+ iso = "%Y-%m-%dT%H:%M%:z"
25
+ hmt = "%H:%M"
26
+ tz_minutes = segments[9].to_i
27
+ tz_offset = tz_offset_hours >= 0 ? "+" : "-"
28
+ tz_offset = tz_offset + "#{double_digit(tz_minutes/60)}:#{double_digit(tz_minutes%60)}"
29
+ date = segments[0].strip
23
30
  day = Hash.new
24
31
  sun = Hash.new
25
32
  moon = Hash.new
26
33
  major_feed_times = Array.new
27
34
  minor_feed_times = Array.new
28
- sun[:rise] = segments[1].strip[0..-4] unless segments[1].strip == "NONE"
29
- sun[:set] = segments[3].strip[0..-4] unless segments[3].strip == "NONE"
30
- sun[:transit] = segments[2].strip[0..-4] unless segments[2].strip == "NONE"
31
- moon[:rise] = segments[5].strip[0..-4] unless segments[5].strip == "NONE"
32
- moon[:set] = segments[7].strip[0..-4] unless segments[7].strip == "NONE"
33
- moon[:transit] = segments[6].strip[0..-4] unless segments[6].strip == "NONE"
34
- day[:under_foot] = segments[8].strip[0..-4] unless segments[8].strip == "NONE"
35
- unless moon[:rise].nil?
36
- minor_feed_times << { start: add_minutes(moon[:rise],-45), stop: add_minutes(moon[:rise],45) }
35
+ sun_rise = Time.parse(date+" "+segments[1].strip[0..-4]+tz_offset) unless segments[1].strip == "NONE"
36
+ sun[:rise] = sun_rise.strftime(hmt) unless sun_rise.nil?
37
+ sun[:rise_at] = sun_rise.strftime(iso) unless sun_rise.nil?
38
+ sun_set = Time.parse(date+" "+segments[3].strip[0..-4]+tz_offset) unless segments[3].strip == "NONE"
39
+ sun[:set] = sun_set.strftime(hmt) unless sun_set.nil?
40
+ sun[:set_at] = sun_set.strftime(iso) unless sun_set.nil?
41
+ sun_transit = Time.parse(date+" "+segments[2].strip[0..-4]+tz_offset) unless segments[2].strip == "NONE"
42
+ sun[:transit] = sun_transit.strftime(hmt) unless sun_transit.nil?
43
+ sun[:transit_at] = sun_transit.strftime(iso) unless sun_transit.nil?
44
+ moon_rise = Time.parse(date+" "+segments[5].strip[0..-4]+tz_offset) unless segments[5].strip == "NONE"
45
+ moon[:rise] = moon_rise.strftime(hmt) unless moon_rise.nil?
46
+ moon[:rise_at] = moon_rise.strftime(iso) unless moon_rise.nil?
47
+ moon_set = Time.parse(date+" "+segments[7].strip[0..-4]+tz_offset) unless segments[7].strip == "NONE"
48
+ moon[:set] = moon_set.strftime(hmt) unless moon_set.nil?
49
+ moon[:set_at] = moon_set.strftime(iso) unless moon_set.nil?
50
+ moon_transit = Time.parse(date+" "+segments[6].strip[0..-4]+tz_offset) unless segments[6].strip == "NONE"
51
+ moon[:transit] = moon_transit.strftime(hmt) unless moon_transit.nil?
52
+ moon[:transit_at] = moon_transit.strftime(iso) unless moon_transit.nil?
53
+ day_under_foot = Time.parse(date+" "+segments[8].strip[0..-4]+tz_offset) unless segments[8].strip == "NONE"
54
+ day[:under_foot] = day_under_foot.strftime(hmt) unless day_under_foot.nil?
55
+ day[:under_foot_at] = day_under_foot.strftime(iso) unless day_under_foot.nil?
56
+ unless moon_rise.nil?
57
+ minor_feed_times << {
58
+ start: (moon_rise-45*60).strftime(hmt),
59
+ start_at: (moon_rise-45*60).strftime(iso),
60
+ stop: (moon_rise+45*60).strftime(hmt),
61
+ stop_at: (moon_rise+45*60).strftime(iso)
62
+ }
37
63
  end
38
- unless moon[:set].nil?
39
- minor_feed_times << { start: add_minutes(moon[:set],-45), stop: add_minutes(moon[:set],45) }
64
+ unless moon_set.nil?
65
+ minor_feed_times << {
66
+ start: (moon_set-45*60).strftime(hmt),
67
+ start_at: (moon_set-45*60).strftime(iso),
68
+ stop: (moon_set+45*60).strftime(hmt),
69
+ stop_at: (moon_set+45*60).strftime(iso)
70
+ }
40
71
  end
41
- unless moon[:rise].nil? || moon[:set].nil? || moon[:rise].split(":").first.to_i < moon[:set].split(":").first.to_i
72
+ unless moon_rise.nil? || moon_set.nil? || moon_rise < moon_set
42
73
  minor_feed_times.rotate!
43
74
  end
44
- unless moon[:transit].nil?
45
- major_feed_times << { start: add_minutes(moon[:transit],-90), stop: add_minutes(moon[:transit],90) }
75
+ unless moon_transit.nil?
76
+ major_feed_times << {
77
+ start: (moon_transit-90*60).strftime(hmt),
78
+ start_at: (moon_transit-90*60).strftime(iso),
79
+ stop: (moon_transit+90*60).strftime(hmt),
80
+ stop_at: (moon_transit+90*60).strftime(iso)
81
+ }
46
82
  end
47
- unless day[:under_foot].nil?
48
- major_feed_times << { start: add_minutes(day[:under_foot],-90), stop: add_minutes(day[:under_foot],90) }
83
+ unless day_under_foot.nil?
84
+ major_feed_times << {
85
+ start: (day_under_foot-90*60).strftime(hmt),
86
+ start_at: (day_under_foot-90*60).strftime(iso),
87
+ stop: (day_under_foot+90*60).strftime(hmt),
88
+ stop_at: (day_under_foot+90*60).strftime(iso)
89
+ }
49
90
  end
50
- unless moon[:transit].nil? || day[:under_foot].nil? || moon[:transit].split(":").first.to_i < day[:under_foot].split(":").first.to_i
91
+ unless moon_transit.nil? || day_under_foot.nil? || moon_transit < day_under_foot
51
92
  major_feed_times.rotate!
52
93
  end
53
- day[:date] = segments[0].strip
94
+ day[:date] = date
95
+ day[:timestamp] = Time.parse(date+" 00:00:00"+tz_offset).strftime(iso)
54
96
  day[:moon_illumination] = segments[12].strip
55
97
  day[:moon_phase] = segments[10].strip
56
98
  day[:moon] = moon
@@ -62,41 +104,14 @@ class Solunar
62
104
  forecast
63
105
  end
64
106
 
65
- def add_hours(str,num)
66
- segs = str.split(":")
67
- hour = segs[0].to_i
68
- hour += num
69
- hour += 24 if hour < 0
70
- hour -= 24 if hour > 23
71
- if hour > 9
72
- return "#{hour.to_s}:#{segs[1]}"
73
- else
74
- return "0#{hour.to_s}:#{segs[1]}"
75
- end
76
- end
77
-
78
- def add_minutes(str,num)
79
- segs = str.split(":")
80
- hour = segs[0].to_i
81
- minutes = segs[1].to_i
82
- minutes += num
83
- while(minutes > 59)
84
- minutes -= 60
85
- hour += 1
86
- end
87
- while(minutes < 0)
88
- minutes += 60
89
- hour -= 1
90
- end
91
- minutes = "0".to_s + minutes.to_s if minutes < 10
92
- hour += 24 if hour < 0
93
- hour -= 24 if hour > 23
94
- if hour > 9
95
- return "#{hour.to_s}:#{minutes.to_s}"
107
+ def double_digit(num)
108
+ if num > 9 || num < -9
109
+ return num.to_s
96
110
  else
97
- return "0#{hour.to_s}:#{minutes.to_s}"
111
+ return "0#{num.abs.to_s}"
98
112
  end
99
113
  end
100
114
 
101
115
  end
116
+
102
117
  require 'solunar/solunar'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solunar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - "\"Sullivan"
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-12-01 00:00:00.000000000 Z
13
+ date: 2017-01-04 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: A gem that wraps the C code from Rick Dawson that computes the sun and
16
16
  moon times based on date and coordinates. Takes a series of arguments, and returns
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  version: '0'
79
79
  requirements: []
80
80
  rubyforge_project:
81
- rubygems_version: 2.6.8
81
+ rubygems_version: 2.5.2
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: Solunar Forecasting Gem