horoscope 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ output.png
data/Gemfile CHANGED
@@ -2,3 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in horoscope.gemspec
4
4
  gemspec
5
+
6
+ gem 'rmagick'
7
+
8
+ group :development, :test do
9
+ gem 'rake'
10
+ end
data/README.md CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  Calculate the accurate horoscope of a person using Vedic Horoscope technique given the birth time and birth place of the subject. The gem is available at https://rubygems.org/gems/horoscope
4
4
 
5
+ [![Travis CI ](https://api.travis-ci.org/bragboy/horoscope.png) ](https://travis-ci.org/bragboy/horoscope)
5
6
  [![Code Climate](https://codeclimate.com/github/bragboy/horoscope.png)](https://codeclimate.com/github/bragboy/horoscope)
6
7
 
7
8
  ## Installation
@@ -22,11 +23,13 @@ Then you can start using this by passing a Time object along with latitude and l
22
23
 
23
24
  #To calculate Sachin Tendulkar's horoscope
24
25
  h = Horoscope::Horo.new(
25
- :datetime => Time.mktime(1973, 4, 24, 14, 25).getlocal("+05:30"),
26
+ :datetime => Time.utc(1973, 4, 24, 14, 25),
27
+ :zone => 5.5,
26
28
  :lat => 18.60, :lon => -72.50)
27
29
  h.compute
28
30
  => {"As"=>4, "Su"=>0, "Mo"=>8, "Ma"=>9, "Me"=>11, "Ju"=>9, "Ve"=>0, "Sa"=>1, "Ra"=>8, "Ke"=>2}
29
31
 
32
+ h.create_chart #This will generate the horoscope chart to your working directory
30
33
 
31
34
  ## Contributing
32
35
 
Binary file
@@ -10,8 +10,11 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["bragboy@gmail.com"]
11
11
  gem.description = %q{Calculate the horoscope of a person given the birth date and time}
12
12
  gem.summary = %q{Calculate the accurate horoscope of a person using Vedic Horoscope technique given the birth time and birth place of the subject.}
13
- gem.homepage = ""
13
+ gem.homepage = "https://github.com/bragboy/horoscope"
14
+
14
15
  gem.add_development_dependency "rspec"
16
+ gem.add_development_dependency "debugger"
17
+ gem.add_dependency "rmagick"
15
18
 
16
19
  gem.files = `git ls-files`.split($/)
17
20
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -1,30 +1,40 @@
1
1
  require 'horoscope/version'
2
2
  require 'horoscope/overrides/math_override'
3
3
  require 'horoscope/planet'
4
+ require 'RMagick'
4
5
 
5
6
  module Horoscope
6
7
  class Horo
7
8
 
8
9
  PLANETS = ["As", "Su", "Mo", "Ma", "Me", "Ju", "Ve", "Sa", "Ra", "Ke"]
9
10
 
11
+ IMG_SIZE = 440
12
+ SPLIT = IMG_SIZE/4
13
+ XBIAS = 10
14
+ YBIAS = 15
15
+ PADDING = 15
16
+
10
17
  ERRORS = {
11
18
  :Date => "Error: Invalid Date. Enter a valid date between years 1600 AD and 2300 AD",
19
+ :Zone => "Error: Please pass a valid time zone ranging from -12.0 to +12.0",
12
20
  :Lat => "Error: Invalid Latitude. Enter between -90.0 to +90.0",
13
21
  :Lon => "Error: Invalid Longitude. Enter between -180.0 to +180.0"
14
22
  }
15
23
 
16
- attr_accessor :datetime, :lat, :lon, :errors, :positions
24
+ attr_accessor :datetime, :zone, :lat, :lon, :errors, :positions, :positions_rev
17
25
 
18
26
  def initialize(data={})
19
27
  @data = data
20
28
 
21
29
  @errors = []
22
30
 
31
+ @computed = false
23
32
  @datetime = data[:datetime]
24
- @zone = data[:offset]
33
+ @zone = data[:zone]
25
34
  @lat = data[:lat]
26
35
  @lon = data[:lon]
27
36
  @positions = Hash[PLANETS.map {|x| [x, nil]}]
37
+ @positions_rev = [[], [], [], [], [], [], [], [], [], [], [], []]
28
38
  end
29
39
 
30
40
  def compute
@@ -34,7 +44,7 @@ module Horoscope
34
44
  tsp, pos, spd = [Array.new(10, 0), Array.new(10, 0), Array.new(10, 0)]
35
45
  jd = Planet.get_jul_day(@datetime.month, @datetime.day, @datetime.year)
36
46
  time = @datetime.hour + (@datetime.min / 60.0)
37
- time -= @datetime.utc_offset / 3600.0
47
+ time -= @zone
38
48
  jd += time / 24.0
39
49
  t = (jd - 0.5 - Planet::J2000) / 36525.0
40
50
  Planet.get_planets(t, pos, spd)
@@ -49,19 +59,51 @@ module Horoscope
49
59
  end
50
60
  tsp[i] = (spd[i] * 3600.0).to_i
51
61
  end
62
+ count = 0
52
63
  (0..11).each do |i|
53
64
  (0..9).each do |j|
54
- @positions[PLANETS[j]] = i if (tpos[j] / 1800 == i)
65
+ if (tpos[j] / 1800 == i)
66
+ @positions[PLANETS[j]] = i
67
+ @positions_rev[i] << PLANETS[j]
68
+ end
55
69
  end
56
70
  end
71
+ @computed = true
57
72
  return @positions
58
73
  end
59
74
 
75
+ def create_chart(options={})
76
+ self.compute unless @computed
77
+ base_chart = Magick::ImageList.new('assets/south_chart.png')
78
+
79
+ canvas = Magick::ImageList.new
80
+ canvas.new_image(IMG_SIZE, IMG_SIZE, Magick::TextureFill.new(base_chart))
81
+
82
+ draw_x = [XBIAS+SPLIT, XBIAS+SPLIT*2, XBIAS+SPLIT*3, XBIAS+SPLIT*3, XBIAS+SPLIT*3, XBIAS+SPLIT*3, XBIAS+SPLIT*2, XBIAS+SPLIT, XBIAS, XBIAS, XBIAS, XBIAS, XBIAS]
83
+ draw_y = [YBIAS, YBIAS, YBIAS, YBIAS+SPLIT, YBIAS+SPLIT*2, YBIAS+SPLIT*3, YBIAS+SPLIT*3, YBIAS+SPLIT*3, YBIAS+SPLIT*3, YBIAS+SPLIT*2, YBIAS+SPLIT, YBIAS]
84
+
85
+ text = Magick::Draw.new
86
+ text.pointsize = 14
87
+ text.font_family = 'helvetica'
88
+
89
+ @positions_rev.each_with_index do |this_pos, i|
90
+ unless this_pos.empty?
91
+ this_pos.each_with_index do |planet, j|
92
+ text.annotate(canvas, 0, 0, draw_x[i], draw_y[i] + j * PADDING, planet) {
93
+ self.fill = planet == PLANETS[0] ? 'red' : 'black'
94
+ }
95
+ end
96
+ end
97
+ end
98
+ x = canvas.write('output.png')
99
+ end
100
+
60
101
  private
61
102
 
62
103
  def validate_values
63
104
  @errors = []
64
105
  @errors << ERRORS[:Date] if @datetime.nil? || !@datetime.is_a?(Time) || @datetime.year > 2300 || @datetime.year < 1600
106
+ @errors << ERRORS[:Zone] if @zone.nil? || @zone > 12.0 || @zone < -12.0
65
107
  @errors << ERRORS[:Lat] if @lat.nil? || @lat > 90.0 || @lat < -90.0
66
108
  @errors << ERRORS[:Lon] if @lon.nil? || @lon > 180.0 || @lon < -180.0
67
109
  @errors
@@ -1,3 +1,3 @@
1
1
  module Horoscope
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,53 +1,77 @@
1
1
  require 'spec_helper'
2
+ require 'ruby-debug'
2
3
 
3
4
  describe Horoscope do
4
5
  it "should error out for blanks" do
5
- h = Horoscope::Horo.new
6
- expect(h.compute).to eql(["Error: Invalid Date. Enter a valid date between years 1600 AD and 2300 AD",
7
- "Error: Invalid Latitude. Enter between -90.0 to +90.0",
8
- "Error: Invalid Longitude. Enter between -180.0 to +180.0"])
6
+ h = Horoscope::Horo.new
7
+ expect(h.compute).to eql(["Error: Invalid Date. Enter a valid date between years 1600 AD and 2300 AD",
8
+ "Error: Please pass a valid time zone ranging from -12.0 to +12.0",
9
+ "Error: Invalid Latitude. Enter between -90.0 to +90.0",
10
+ "Error: Invalid Longitude. Enter between -180.0 to +180.0"])
9
11
  end
10
12
 
11
13
  it "should validate an universal horoscope" do
12
- #Sachin Tendulkar's Birth Horoscope
13
- h = Horoscope::Horo.new(:datetime => Time.mktime(1973, 4, 24, 14, 25).getlocal("+05:30"), :lat => 18.60, :lon => -72.50)
14
- h.compute
15
- expect(h.errors).to eql([])
16
- expect(h.positions).to eql({"As"=>4, "Su"=>0, "Mo"=>8, "Ma"=>9, "Me"=>11, "Ju"=>9, "Ve"=>0, "Sa"=>1, "Ra"=>8, "Ke"=>2})
14
+ #Sachin Tendulkar's Birth Horoscope
15
+ h = Horoscope::Horo.new(:datetime => Time.utc(1973, 4, 24, 14, 25), :zone => +5.5, :lat => 18.60, :lon => -72.50)
16
+ h.compute
17
+ expect(h.errors).to eql([])
18
+ expect(h.positions).to eql({"As"=>4, "Su"=>0, "Mo"=>8, "Ma"=>9, "Me"=>11, "Ju"=>9, "Ve"=>0, "Sa"=>1, "Ra"=>8, "Ke"=>2})
17
19
  end
18
20
 
19
21
  it "should validate all dates" do
20
- h = Horoscope::Horo.new(:datetime => nil, :lat => 0, :lon => 0)
21
- expect(h.compute).to eql(["Error: Invalid Date. Enter a valid date between years 1600 AD and 2300 AD"])
22
+ h = Horoscope::Horo.new(:datetime => nil, :zone => 0, :lat => 0, :lon => 0)
23
+ expect(h.compute).to eql(["Error: Invalid Date. Enter a valid date between years 1600 AD and 2300 AD"])
22
24
 
23
- h.datetime = Time.mktime(1599)
24
- expect(h.compute).to eql(["Error: Invalid Date. Enter a valid date between years 1600 AD and 2300 AD"])
25
+ h.datetime = Time.mktime(1599)
26
+ expect(h.compute).to eql(["Error: Invalid Date. Enter a valid date between years 1600 AD and 2300 AD"])
25
27
 
26
- h.datetime = Time.mktime(2301)
27
- expect(h.compute).to eql(["Error: Invalid Date. Enter a valid date between years 1600 AD and 2300 AD"])
28
-
29
- h.datetime = Time.mktime(2013)
28
+ h.datetime = Time.mktime(2301)
29
+ expect(h.compute).to eql(["Error: Invalid Date. Enter a valid date between years 1600 AD and 2300 AD"])
30
+
31
+ h.datetime = Time.mktime(2013)
30
32
  h.compute
31
- expect(h.errors).to eql([])
33
+ expect(h.errors).to eql([])
32
34
  end
33
35
 
34
36
  it "should validate lat and lon" do
35
- h = Horoscope::Horo.new(:datetime => Time.now)
36
- expect(h.compute).to eql(["Error: Invalid Latitude. Enter between -90.0 to +90.0",
37
- "Error: Invalid Longitude. Enter between -180.0 to +180.0"])
38
-
39
- h.lat = +90.1
40
- h.lon = +180.1
41
- expect(h.compute).to eql(["Error: Invalid Latitude. Enter between -90.0 to +90.0",
42
- "Error: Invalid Longitude. Enter between -180.0 to +180.0"])
43
-
44
- h.lat = -90.1
45
- h.lon = -180.1
46
- expect(h.compute).to eql(["Error: Invalid Latitude. Enter between -90.0 to +90.0",
47
- "Error: Invalid Longitude. Enter between -180.0 to +180.0"])
48
-
49
- h.lat = h.lon = 0
50
- h.compute
51
- expect(h.errors).to eql([])
37
+ h = Horoscope::Horo.new(:datetime => Time.now, :zone => 0)
38
+ expect(h.compute).to eql(["Error: Invalid Latitude. Enter between -90.0 to +90.0",
39
+ "Error: Invalid Longitude. Enter between -180.0 to +180.0"])
40
+
41
+ h.lat = +90.1
42
+ h.lon = +180.1
43
+ expect(h.compute).to eql(["Error: Invalid Latitude. Enter between -90.0 to +90.0",
44
+ "Error: Invalid Longitude. Enter between -180.0 to +180.0"])
45
+
46
+ h.lat = -90.1
47
+ h.lon = -180.1
48
+ expect(h.compute).to eql(["Error: Invalid Latitude. Enter between -90.0 to +90.0",
49
+ "Error: Invalid Longitude. Enter between -180.0 to +180.0"])
50
+
51
+ h.lat = h.lon = 0
52
+ h.compute
53
+ expect(h.errors).to eql([])
54
+ end
55
+
56
+ it "should validate time zone" do
57
+ h = Horoscope::Horo.new(:datetime => Time.now, :lat => 18.60, :lon => -72.50)
58
+ expect(h.compute).to eql(["Error: Please pass a valid time zone ranging from -12.0 to +12.0"])
59
+
60
+ h.zone = -12.1
61
+ expect(h.compute).to eql(["Error: Please pass a valid time zone ranging from -12.0 to +12.0"])
62
+
63
+ h.zone = 12.1
64
+ expect(h.compute).to eql(["Error: Please pass a valid time zone ranging from -12.0 to +12.0"])
65
+
66
+ h.zone = 5.5
67
+ h.compute
68
+ expect(h.errors).to eql([])
69
+ end
70
+
71
+ it "can generate chart" do
72
+ h = Horoscope::Horo.new(:datetime => Time.mktime(1973, 4, 24, 14, 25).getlocal("+05:30"), :lat => 18.60, :lon => -72.50)
73
+ h.compute
74
+ h.create_chart
75
+ expect(File).to exist("output.png")
52
76
  end
53
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: horoscope
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -27,6 +27,38 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: debugger
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rmagick
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
30
62
  description: Calculate the horoscope of a person given the birth date and time
31
63
  email:
32
64
  - bragboy@gmail.com
@@ -41,6 +73,7 @@ files:
41
73
  - LICENSE.txt
42
74
  - README.md
43
75
  - Rakefile
76
+ - assets/south_chart.png
44
77
  - horoscope.gemspec
45
78
  - lib/horoscope.rb
46
79
  - lib/horoscope/overrides/math_override.rb
@@ -56,7 +89,7 @@ files:
56
89
  - lib/horoscope/version.rb
57
90
  - spec/horoscope_spec.rb
58
91
  - spec/spec_helper.rb
59
- homepage: ''
92
+ homepage: https://github.com/bragboy/horoscope
60
93
  licenses: []
61
94
  post_install_message:
62
95
  rdoc_options: []