Class: Astroscript::Chart
- Inherits:
-
Object
- Object
- Astroscript::Chart
show all
- Defined in:
- lib/astroscript/chart.rb
Constant Summary
collapse
- DEFAULT_BODIES =
AstroHelper::PLANETS + AstroHelper::EXTRAS - [:VX]
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#[](abbr) ⇒ Object
-
#[]=(key, body) ⇒ Object
-
#aries_point ⇒ Object
-
#asc ⇒ Object
-
#asc=(deg) ⇒ Object
-
#aspects(opts = {}) ⇒ Object
-
#bodies ⇒ Object
-
#conjunctions(orb: 8) ⇒ Object
-
#deg(body, method = :to_f) ⇒ Object
-
#degree(body, asc = nil) ⇒ Object
helper for drawing chart.
-
#find_bodies(ary) ⇒ Object
-
#find_body(abbr) ⇒ Object
-
#find_body!(abbr) ⇒ Object
-
#get_bodies!(planets) ⇒ Object
-
#get_body(abbr) ⇒ Object
-
#harmonic? ⇒ Boolean
-
#harmonize(h) ⇒ Object
(also: #*)
-
#harmonize!(h) ⇒ Object
-
#initialize(birth_data, bodies: DEFAULT_BODIES, opts: {}) ⇒ Chart
constructor
TODO: consider renaming opts to calc(_opts) ?.
-
#initialize_copy(orig) ⇒ Object
-
#method_missing(method_name) ⇒ Object
-
#midpoint_aspects(opts = {}) ⇒ Object
-
#midpoints ⇒ Object
-
#night_birth? ⇒ Boolean
-
#phase_angle(b1, b2) ⇒ Object
-
#print(**opts) ⇒ Object
prefix: true, seconds: true, gate: true, house: true, spectrum: true.
-
#recalc!(opts = {}) ⇒ Object
-
#to_a ⇒ Object
-
#to_json(*_args) ⇒ Object
-
#transformer=(method) ⇒ Object
def dup Chart.new( @calc.dup, @chart.values.map(&:abbr), @opts) end.
-
#trines(orb: 8) ⇒ Object
Constructor Details
#initialize(birth_data, bodies: DEFAULT_BODIES, opts: {}) ⇒ Chart
TODO: consider renaming opts to calc(_opts) ?
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/astroscript/chart.rb', line 11
def initialize(birth_data, bodies: DEFAULT_BODIES, opts: {})
@opts = opts || {}
@opts[:true_node] ||= true
case birth_data
when Astroscript::Chart, Astroscript::Calculator
@calc = birth_data.dup
@calc.house_method = opts[:house_method]
@calc = @calc.calc if @calc.is_a?(Chart)
when Array
@calc = Astroscript::Calculator.new(opts).init(birth_data)
@location, name = birth_data[5..6]
when nil
raise ArgumentError, "no birth data provided!"
end
self.transformer = opts[:transformer]
@chart = {}
@harmonic = opts[:harmonic] || 1
@calc.arc = opts[:arc] if opts[:arc]
@calc.name = name || opts[:name] || ""
@calc.prefix = opts[:prefix]
get_bodies! bodies
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name) ⇒ Object
143
144
145
146
147
148
149
150
151
|
# File 'lib/astroscript/chart.rb', line 143
def method_missing(method_name, ...)
if @calc.respond_to?(method_name)
@calc.send(method_name, ...)
elsif @chart.respond_to?(method_name)
@chart.send(method_name, ...)
else
raise "unknown method! :#{method_name}"
end
end
|
Instance Attribute Details
#calc ⇒ Object
Returns the value of attribute calc.
5
6
7
|
# File 'lib/astroscript/chart.rb', line 5
def calc
@calc
end
|
#harmonic ⇒ Object
Returns the value of attribute harmonic.
6
7
8
|
# File 'lib/astroscript/chart.rb', line 6
def harmonic
@harmonic
end
|
#location ⇒ Object
Returns the value of attribute location.
6
7
8
|
# File 'lib/astroscript/chart.rb', line 6
def location
@location
end
|
Instance Method Details
#[](abbr) ⇒ Object
110
111
112
113
|
# File 'lib/astroscript/chart.rb', line 110
def [](abbr)
abbr = abbr.upcase if abbr.size == 2
get_body(abbr)
end
|
#[]=(key, body) ⇒ Object
105
106
107
108
|
# File 'lib/astroscript/chart.rb', line 105
def []=(key, body)
@chart[key] = body
end
|
#aries_point ⇒ Object
138
139
140
141
|
# File 'lib/astroscript/chart.rb', line 138
def aries_point
0
end
|
#asc ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'lib/astroscript/chart.rb', line 63
def asc
return @asc if @asc
if (a = find_body(:AC) || find_body(:C1))
a.degree
else
@calc.asc
end
end
|
#asc=(deg) ⇒ Object
59
60
61
|
# File 'lib/astroscript/chart.rb', line 59
def asc=(deg)
@asc = deg.to_f
end
|
#aspects(opts = {}) ⇒ Object
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/astroscript/chart.rb', line 196
def aspects(opts = {})
_bodies = bodies + opts[:with].to_a
if (orbs = opts[:orbs])
orbs.map do |flavor, orb|
_bodies.combination(2).map do |b1, b2|
Aspect.new(b1, b2, orb: orb, ratio: Aspect::FLAVORS.key(flavor))
end
end.flatten.uniq
else
_bodies.combination(2).map do |b1, b2|
Aspect.new(b1, b2, opts)
end.reject(&:invalid?)
end
end
|
#bodies ⇒ Object
49
50
51
|
# File 'lib/astroscript/chart.rb', line 49
def bodies
@chart.values
end
|
#conjunctions(orb: 8) ⇒ Object
211
212
213
|
# File 'lib/astroscript/chart.rb', line 211
def conjunctions(orb: 8)
aspects(orb: orb, harmonic: 1)
end
|
#deg(body, method = :to_f) ⇒ Object
73
74
75
|
# File 'lib/astroscript/chart.rb', line 73
def deg(body, method = :to_f)
body.send(method)
end
|
#degree(body, asc = nil) ⇒ Object
77
78
79
|
# File 'lib/astroscript/chart.rb', line 77
def degree(body, asc = nil) ((asc || self.asc) - 180 - deg(body)) % 360
end
|
#find_bodies(ary) ⇒ Object
134
135
136
|
# File 'lib/astroscript/chart.rb', line 134
def find_bodies(ary)
ary.map{|a| find_body(a) }
end
|
#find_body(abbr) ⇒ Object
115
116
117
118
119
120
121
|
# File 'lib/astroscript/chart.rb', line 115
def find_body(abbr)
if (result = @chart.find{|_k, v| v.abbr == abbr })
result[1]
else
end
end
|
#find_body!(abbr) ⇒ Object
#get_bodies!(planets) ⇒ Object
81
82
83
84
85
86
|
# File 'lib/astroscript/chart.rb', line 81
def get_bodies!(planets)
planets.each do |abbr|
body = find_body!(abbr)
body.harmonize!(@harmonic) if body.is_a?(Astroscript::Body)
end
end
|
#get_body(abbr) ⇒ Object
123
124
125
126
127
128
129
130
131
132
|
# File 'lib/astroscript/chart.rb', line 123
def get_body(abbr)
body = SwissEphemeris::BODIES[abbr]
if (method = body[:method])
method = body[:name] if method == true
output = MethodBody.new(send(method), method, chart: self)
else
output = find_body(abbr) || calc.get_body(abbr)
end
output.harmonize(@harmonic)
end
|
#harmonic? ⇒ Boolean
163
164
165
|
# File 'lib/astroscript/chart.rb', line 163
def harmonic?
@harmonic > 1
end
|
#harmonize(h) ⇒ Object
Also known as:
*
167
168
169
170
171
|
# File 'lib/astroscript/chart.rb', line 167
def harmonize(h)
output = initialize_copy(self)
output.harmonize!(h)
end
|
#harmonize!(h) ⇒ Object
173
174
175
176
177
|
# File 'lib/astroscript/chart.rb', line 173
def harmonize!(h)
@harmonic = h
bodies.each{|b| b.harmonize!(h) }
self
end
|
#initialize_copy(orig) ⇒ Object
34
35
36
37
38
39
|
# File 'lib/astroscript/chart.rb', line 34
def initialize_copy(orig)
super
@calc = @calc.dup self
end
|
#midpoint_aspects(opts = {}) ⇒ Object
225
226
227
228
229
230
231
232
|
# File 'lib/astroscript/chart.rb', line 225
def midpoint_aspects(opts = {})
opts[:max_harmonic] ||= 2
opts[:orb] ||= 1.5
aspects(opts.merge(with: midpoints))
.select(&:midpoint?)
.reject(&:overlap?).reject(&:isotrap?)
.sort_by(&:orb)
end
|
#midpoints ⇒ Object
219
220
221
222
223
|
# File 'lib/astroscript/chart.rb', line 219
def midpoints
bodies.combination(2).map do |b1, b2|
Midpoint.new(b1, b2)
end
end
|
#night_birth? ⇒ Boolean
153
154
155
156
157
158
159
160
161
|
# File 'lib/astroscript/chart.rb', line 153
def night_birth?
sun = get_body(:SO).lon
desc = asc + 180
if desc > 360
sun.between?(desc % 360, asc)
else
sun.between?(asc, asc + 180)
end
end
|
#phase_angle(b1, b2) ⇒ Object
98
99
100
101
102
103
|
# File 'lib/astroscript/chart.rb', line 98
def phase_angle(b1, b2)
b1 = find_body(b1) if b1.is_a?(Symbol) && SwissEphemeris::BODIES.keys.include?(b1)
b2 = find_body(b2) if b2.is_a?(Symbol) && SwissEphemeris::BODIES.keys.include?(b2)
b1 - b2
end
|
#print(**opts) ⇒ Object
prefix: true, seconds: true, gate: true, house: true, spectrum: true
181
182
183
184
|
# File 'lib/astroscript/chart.rb', line 181
def print **opts opts[:seconds] ||= true
puts @chart.map{|_k, v| v.to_s(opts) }.join("\n")
end
|
#recalc!(opts = {}) ⇒ Object
53
54
55
56
57
|
# File 'lib/astroscript/chart.rb', line 53
def recalc!(opts = {})
@calc.update(opts) unless opts.empty?
bodies.each(&:calculate!)
self
end
|
#to_a ⇒ Object
186
187
188
|
# File 'lib/astroscript/chart.rb', line 186
def to_a
calc.to_a << location
end
|
#to_json(*_args) ⇒ Object
190
191
192
193
194
|
# File 'lib/astroscript/chart.rb', line 190
def to_json(*_args)
{
bodies: bodies.map(&:to_json)
}.to_json
end
|
def dup
Chart.new( @calc.dup, @chart.values.map(&:abbr), @opts)
end
45
46
47
|
# File 'lib/astroscript/chart.rb', line 45
def transformer=(method)
@calc.transformer = method
end
|
#trines(orb: 8) ⇒ Object
215
216
217
|
# File 'lib/astroscript/chart.rb', line 215
def trines(orb: 8)
aspects(orb: orb, harmonic: 3)
end
|