rballista 0.0.1
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/README +3 -0
- data/lib/ballista.rb +110 -0
- metadata +54 -0
data/README
ADDED
data/lib/ballista.rb
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Checks the supplied date elements to determine if they comprise a
|
|
2
|
+
# valid date. At present, the +hr+ and +min+ parameters are ignored.
|
|
3
|
+
def are_date_details_valid?(y, m, d, hr, min)
|
|
4
|
+
if y < 1900 or y > 2050
|
|
5
|
+
return false
|
|
6
|
+
end
|
|
7
|
+
if m < 1 or m > 12
|
|
8
|
+
return false
|
|
9
|
+
end
|
|
10
|
+
if d < 1
|
|
11
|
+
return false
|
|
12
|
+
end
|
|
13
|
+
if m == 2
|
|
14
|
+
if is_leap_year(y)
|
|
15
|
+
if d > 29
|
|
16
|
+
return false
|
|
17
|
+
end
|
|
18
|
+
else
|
|
19
|
+
if d > 28
|
|
20
|
+
return false
|
|
21
|
+
end
|
|
22
|
+
end # is_leap_year
|
|
23
|
+
end # m == 2 (Feb)
|
|
24
|
+
|
|
25
|
+
if ([4,6,9,11].include?(m))
|
|
26
|
+
if d > 30
|
|
27
|
+
return false
|
|
28
|
+
end
|
|
29
|
+
else
|
|
30
|
+
if d > 31
|
|
31
|
+
return false
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
return true
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Checks if the supplied year value is a leap year or not. Allows for
|
|
40
|
+
# centuries and centuries that are factors of 400.
|
|
41
|
+
def is_leap_year(y)
|
|
42
|
+
is_leap = false
|
|
43
|
+
if y % 4 == 0
|
|
44
|
+
is_leap = true
|
|
45
|
+
if y % 100 == 0
|
|
46
|
+
is_leap = false
|
|
47
|
+
if y % 400 == 0
|
|
48
|
+
is_leap = true
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
is_leap
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Creates a ballista compliant date out of a normal date/time
|
|
56
|
+
def make_ballista_date(t)
|
|
57
|
+
t.strftime("%Y%m%d%H%M")
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Translates a ballista date to match YYYY-MM-DD hh:mm:ss
|
|
61
|
+
def translate_ballista_date(bd)
|
|
62
|
+
# Ballista date
|
|
63
|
+
# 0123456789012345678
|
|
64
|
+
# 197009300730
|
|
65
|
+
# 30/09/1970 07:30:00
|
|
66
|
+
# 1970-09-30 07:30:00
|
|
67
|
+
logger.info "translate_ballista_date(#{bd})"
|
|
68
|
+
bd[0..1] + "-" + bd[4..5] + "-" + bd[6..7] + " " + bd[8..9] + ":" + bd[10..11]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Translate a standard date to SQL format
|
|
72
|
+
def make_sql_date(t)
|
|
73
|
+
t.strftime("%Y-%m-%d %H:%M:%S")
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
Planet_Names = { 0 => 'Sun', 1 => 'Moon', 2 => 'Mercury',
|
|
77
|
+
3 => 'Venus', 4 => 'Mars', 5 => 'Jupiter',
|
|
78
|
+
6 => 'Saturn', 7 => 'Uranus', 8 => 'Neptune',
|
|
79
|
+
9 => 'Pluto' }
|
|
80
|
+
|
|
81
|
+
Aspect_Names = { '1' => 'Conjuncts', '2' => 'Opposes', '3' => 'Squares',
|
|
82
|
+
'4' => 'Trines', '5' => 'Sextiles', '6' => 'Semi-sextiles',
|
|
83
|
+
'7' => 'Quincunxes', '8' => 'Semiquintiles', '9' => 'Quintiles',
|
|
84
|
+
'A' => 'Biquintiles', 'B' => 'Semisquares', 'C' => 'Sesquisquares' }
|
|
85
|
+
|
|
86
|
+
Aspect_Names2 = { '1' => 'conjunction', '2' => 'opposition', '3' => 'square',
|
|
87
|
+
'4' => 'trine', '5' => 'sextile', '6' => 'semisextile',
|
|
88
|
+
'7' => 'quincunx', '8' => 'semiquintile', # semi-quintile - no symbol
|
|
89
|
+
'9' => 'quintile',
|
|
90
|
+
'A' => 'biquintile', 'B' => 'semisquare', 'C' => 'sesquisquare' }
|
|
91
|
+
|
|
92
|
+
def translate_aspect(asp_num)
|
|
93
|
+
asp_name = Aspect_Names[asp_num]
|
|
94
|
+
return Aspect_Names[asp_num] if not Aspect_Names[asp_num].nil?
|
|
95
|
+
return "#{asp_num}"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def translate_aspect2(asp_num)
|
|
99
|
+
asp_name = Aspect_Names2[asp_num]
|
|
100
|
+
return Aspect_Names2[asp_num] if not Aspect_Names2[asp_num].nil?
|
|
101
|
+
return "#{asp_num}"
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def translate_planet(plan_num)
|
|
105
|
+
if plan_num >= 0 and plan_num <= 9
|
|
106
|
+
Planet_Names[plan_num]
|
|
107
|
+
else
|
|
108
|
+
""
|
|
109
|
+
end
|
|
110
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rballista
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tim Whelan
|
|
8
|
+
autorequire: ballista
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2009-01-06 00:00:00 +02:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
16
|
+
description:
|
|
17
|
+
email: tim @nospam@ suntail.net
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
20
|
+
extensions: []
|
|
21
|
+
|
|
22
|
+
extra_rdoc_files:
|
|
23
|
+
- README
|
|
24
|
+
files:
|
|
25
|
+
- lib/ballista.rb
|
|
26
|
+
- README
|
|
27
|
+
has_rdoc: true
|
|
28
|
+
homepage:
|
|
29
|
+
post_install_message:
|
|
30
|
+
rdoc_options: []
|
|
31
|
+
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: "0"
|
|
39
|
+
version:
|
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
41
|
+
requirements:
|
|
42
|
+
- - ">="
|
|
43
|
+
- !ruby/object:Gem::Version
|
|
44
|
+
version: "0"
|
|
45
|
+
version:
|
|
46
|
+
requirements: []
|
|
47
|
+
|
|
48
|
+
rubyforge_project:
|
|
49
|
+
rubygems_version: 1.2.0
|
|
50
|
+
signing_key:
|
|
51
|
+
specification_version: 2
|
|
52
|
+
summary: Ballista Utility Functions.
|
|
53
|
+
test_files: []
|
|
54
|
+
|