Class: Horoscope::Horo
- Inherits:
-
Object
- Object
- Horoscope::Horo
- Defined in:
- lib/horoscope.rb
Constant Summary collapse
- PLANETS =
["As", "Su", "Mo", "Ma", "Me", "Ju", "Ve", "Sa", "Ra", "Ke"]
- IMG_SIZE =
440
- SPLIT =
IMG_SIZE/4
- XBIAS =
10
- YBIAS =
15
- PADDING =
15
- CENTER_PADDING =
40
- ERRORS =
{ :Date => "Error: Invalid Date. Enter a valid date between years 1600 AD and 2300 AD", :Zone => "Error: Please pass a valid time zone ranging from -12.0 to +12.0", :Lat => "Error: Invalid Latitude. Enter between -90.0 to +90.0", :Lon => "Error: Invalid Longitude. Enter between -180.0 to +180.0" }
Instance Attribute Summary collapse
-
#datetime ⇒ Object
Returns the value of attribute datetime.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lon ⇒ Object
Returns the value of attribute lon.
-
#positions ⇒ Object
Returns the value of attribute positions.
-
#positions_rev ⇒ Object
Returns the value of attribute positions_rev.
-
#zone ⇒ Object
Returns the value of attribute zone.
Instance Method Summary collapse
- #compute ⇒ Object
- #create_chart(options = {}) ⇒ Object
-
#initialize(data = {}) ⇒ Horo
constructor
A new instance of Horo.
Constructor Details
permalink #initialize(data = {}) ⇒ Horo
Returns a new instance of Horo.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/horoscope.rb', line 33 def initialize(data={}) @data = data @errors = [] @computed = false @datetime = data[:datetime] @zone = data[:zone] @lat = data[:lat] @lon = data[:lon] @positions = Hash[PLANETS.map {|x| [x, nil]}] @positions_rev = [[], [], [], [], [], [], [], [], [], [], [], []] end |
Instance Attribute Details
permalink #datetime ⇒ Object
Returns the value of attribute datetime.
31 32 33 |
# File 'lib/horoscope.rb', line 31 def datetime @datetime end |
permalink #errors ⇒ Object
Returns the value of attribute errors.
31 32 33 |
# File 'lib/horoscope.rb', line 31 def errors @errors end |
permalink #lat ⇒ Object
Returns the value of attribute lat.
31 32 33 |
# File 'lib/horoscope.rb', line 31 def lat @lat end |
permalink #lon ⇒ Object
Returns the value of attribute lon.
31 32 33 |
# File 'lib/horoscope.rb', line 31 def lon @lon end |
permalink #positions ⇒ Object
Returns the value of attribute positions.
31 32 33 |
# File 'lib/horoscope.rb', line 31 def positions @positions end |
permalink #positions_rev ⇒ Object
Returns the value of attribute positions_rev.
31 32 33 |
# File 'lib/horoscope.rb', line 31 def positions_rev @positions_rev end |
permalink #zone ⇒ Object
Returns the value of attribute zone.
31 32 33 |
# File 'lib/horoscope.rb', line 31 def zone @zone end |
Instance Method Details
permalink #compute ⇒ Object
[View source]
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/horoscope.rb', line 47 def compute return @errors if validate_values.size > 0 tpos = [10980, 16233, 15880, 16451, 15210, 13722, 13862, 7676, 4306, 15106] tsp, pos, spd = [Array.new(10, 0), Array.new(10, 0), Array.new(10, 0)] jd = Planet.get_jul_day(@datetime.month, @datetime.day, @datetime.year) time = @datetime.hour + (@datetime.min / 60.0) time -= @zone jd += time / 24.0 t = (jd - 0.5 - Planet::J2000) / 36525.0 Planet.get_planets(t, pos, spd) pos[0] = Planet.ascendant(t, time, @lon, @lat) ayn = Planet.get_ayan(t) (0..9).each do |i| tpos[i] = ((pos[i] + ayn) % 360.0 * 60.0).to_i if tpos[i] < 0 tpos = tpos n = i tpos[n] += 21600 end tsp[i] = (spd[i] * 3600.0).to_i end count = 0 (0..11).each do |i| (0..9).each do |j| if (tpos[j] / 1800 == i) @positions[PLANETS[j]] = i @positions_rev[i] << PLANETS[j] end end end @computed = true return @positions end |
permalink #create_chart(options = {}) ⇒ Object
[View source]
82 83 84 85 86 87 88 89 90 |
# File 'lib/horoscope.rb', line 82 def create_chart(= {}) compute unless @computed case [:format] when :html draw_chart_as_html else draw_chart_as_png end end |