VanaTime 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ == 1.0.0 / 2007-08-20
2
+
3
+ * 1 major enhancement
4
+ * Birthday! Yes, I seriously kept the default history entry.
5
+
data/Manifest.txt ADDED
@@ -0,0 +1,11 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/vana_time.rb
6
+ spec
7
+ spec/spec.opts
8
+ spec/spec_helper.rb
9
+ spec/vana_time_spec.rb
10
+ tasks
11
+ tasks/rspec.rake
data/README.txt ADDED
@@ -0,0 +1,3 @@
1
+ This file is required. Like W.T.F. mate.
2
+ Seriously though, I fail at documentation. The spec should be pretty descriptive about the
3
+ interface to the library.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/vana_time.rb'
6
+
7
+ Hoe.new('VanaTime', VanaTime::VERSION) do |p|
8
+ p.rubyforge_name = 'vanatime'
9
+ p.author = 'Travis Tilley'
10
+ p.email = 'ttilley@gmail.com'
11
+ p.summary = 'Vanadiel time object'
12
+ # p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
13
+ p.description = "A library for converting realtime to vanadiel time"
14
+ # p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
15
+ p.url = "http://vanatime.rubyforge.org"
16
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
17
+ end
18
+
19
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
20
+
21
+ # vim: syntax=Ruby
data/lib/vana_time.rb ADDED
@@ -0,0 +1,124 @@
1
+ class VanaTime
2
+ VERSION = '1.0.0'
3
+
4
+ SECONDS_REAL_DAY = (24 * 60 * 60)
5
+ BASIS_DATE = Time.utc(2002,6,23,15,0,0,0)
6
+
7
+ def initialize(time = Time.now)
8
+ self.earth_time = time
9
+ end
10
+
11
+ def earth_time=(time)
12
+ raise "Input was not a Time object" if ! time.is_a?(Time)
13
+
14
+ @earth_time = time
15
+ @vana_time = ((898 * 360 + 30) * SECONDS_REAL_DAY) +
16
+ (@earth_time.to_i - BASIS_DATE.to_i) * 25
17
+
18
+ @vDate = @vDay = @vHour = @vMin = @vMon = @vMoon = @vSec = @vYear = nil
19
+ end
20
+
21
+ attr_reader :earth_time
22
+
23
+ def self.vana_to_earth(vana_time)
24
+ ((vana_time - ((898 * 360 + 30) * SECONDS_REAL_DAY)) / 25) + BASIS_DATE.to_i
25
+ end
26
+
27
+ def vana_time=(vana_time)
28
+ @vana_time = vana_time
29
+ @earth_time = Time.at(self.class.vana_to_earth(vana_time))
30
+
31
+ @vDate = @vDay = @vHour = @vMin = @vMon = @vMoon = @vSec = @vYear = nil
32
+ end
33
+
34
+ def self.at(vana_time)
35
+ self.new(Time.at(self.vana_to_earth(vana_time)))
36
+ end
37
+
38
+ def to_i
39
+ @vana_time
40
+ end
41
+
42
+ def year
43
+ @vYear ||= (@vana_time / (360 * SECONDS_REAL_DAY))
44
+ end
45
+
46
+ def month
47
+ @vMon ||= ((@vana_time % (360 * SECONDS_REAL_DAY)) /
48
+ (30 * SECONDS_REAL_DAY)) + 1
49
+ end
50
+
51
+ def date
52
+ @vDate ||= ((@vana_time % (30 * SECONDS_REAL_DAY)) /
53
+ (SECONDS_REAL_DAY)) + 1
54
+ end
55
+
56
+ def hour
57
+ @vHour ||= ((@vana_time % (SECONDS_REAL_DAY)) / (60 * 60))
58
+ end
59
+
60
+ def minute
61
+ @vMin ||= ((@vana_time % (60 * 60)) / (60))
62
+ end
63
+
64
+ def second
65
+ @vSec ||= (@vana_time % 60)
66
+ end
67
+
68
+ class VanaDay
69
+ VANA_DAYS = ["Firesday", "Earthsday", "Watersday", "Windsday", "Iceday",
70
+ "Lightningday", "Lightsday", "Darksday"]
71
+ def initialize(vana_time)
72
+ @vanaDay = ((vana_time % (8 * SECONDS_REAL_DAY)) / (SECONDS_REAL_DAY))
73
+ end
74
+ def to_i
75
+ @vanaDay
76
+ end
77
+ def to_s
78
+ VANA_DAYS[@vanaDay]
79
+ end
80
+ end
81
+
82
+ def day
83
+ @vDay ||= VanaDay.new(@vana_time)
84
+ end
85
+
86
+ class VanaMoon
87
+ SECONDS_GAME_DAY = (24 * 60 * 60 / 25)
88
+ MOON_DATE = Time.utc(2004,1,25,2,31,12,0)
89
+ def initialize(time)
90
+ moon_days = ((time.to_i - MOON_DATE.to_i) / SECONDS_GAME_DAY).floor % 84
91
+ moon_days += 84 if moon_days < 0
92
+ @moonPercent = - ((42 - moon_days).to_f / 42 * 100).round
93
+ end
94
+ def to_i
95
+ @moonPercent
96
+ end
97
+ def to_s
98
+ if (@moonPercent == -100)
99
+ "100% Full Moon"
100
+ elsif (@moonPercent == 0)
101
+ "0% New Moon"
102
+ elsif (@moonPercent < 0)
103
+ "#{-@moonPercent}% Waning"
104
+ elsif (@moonPercent > 0)
105
+ "#{@moonPercent}% Waxing"
106
+ end
107
+ end
108
+ end
109
+
110
+ def moon_phase
111
+ @vMoon ||= VanaMoon.new(@earth_time)
112
+ end
113
+
114
+ def self.now
115
+ self.new
116
+ end
117
+
118
+ def to_s
119
+ "Vanadiel Time: #{day} #{year}-#{month}-#{date}" +
120
+ " #{hour}:#{minute}:#{second}" + "\n" + "Moon Phase: #{moon_phase}" +
121
+ "\n" + "Earth Time: #{earth_time.httpdate}"
122
+ end
123
+
124
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ gem 'rspec'
6
+ require 'spec'
7
+ end
8
+
9
+ require File.dirname(__FILE__) + '/../lib/vana_time.rb'
@@ -0,0 +1,86 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe VanaTime do
4
+ before(:all) do
5
+ # this specific date translates to: seconds since vana epoch date ->
6
+ # 32009656750, vana year -> 1029, vana month -> 2, vana date -> 13, vana day
7
+ # of the week -> 2 (base 0) or Watersday, vana minute -> 19, vana hour -> 3,
8
+ # vana second -> 10, vana moon phase -> 62% waxing
9
+ @time = Time.utc(2007,8,23,12,15,10,10)
10
+ @vanatime = VanaTime.new(@time)
11
+ end
12
+
13
+ it "should raise an error when given invalid input" do
14
+ lambda {VanaTime.new("COWS")}.should raise_error
15
+ end
16
+
17
+ it "should provide an accessor for the earth time used to create the object" do
18
+ @vanatime.earth_time.should == @time
19
+ @vanatime.earth_time.class.should == Time
20
+ end
21
+
22
+ it "should use the current time if not initialized with a specific time" do
23
+ def Time.now
24
+ Time.utc(2007,8,23,12,15,10,10)
25
+ end
26
+ vanatime = VanaTime.new
27
+ vanatime.earth_time.should == Time.utc(2007,8,23,12,15,10,10)
28
+ end
29
+
30
+ it "to_i should return the vana time used in all other calculations as an int" do
31
+ @vanatime.to_i.is_a?(Integer).should == true
32
+ @vanatime.to_i.should == 32009656750
33
+ end
34
+
35
+ it "should provide accessor for vana year" do
36
+ @vanatime.year.to_i.should == 1029
37
+ end
38
+
39
+ it "should provide accessor for vana month" do
40
+ @vanatime.month.to_i.should == 2
41
+ end
42
+
43
+ it "should provide accessor for vana date" do
44
+ @vanatime.date.to_i.should == 13
45
+ end
46
+
47
+ it "should provide accessor for vana hour" do
48
+ @vanatime.hour.to_i.should == 3
49
+ end
50
+
51
+ it "should provide accessor for vana minute" do
52
+ @vanatime.minute.to_i.should == 19
53
+ end
54
+
55
+ it "should provide accessor for vana second" do
56
+ @vanatime.second.to_i.should == 10
57
+ end
58
+
59
+ it "should provide accessor for day of week" do
60
+ @vanatime.day.to_s.should == "Watersday"
61
+ end
62
+
63
+ it "should provide accessor for moon percent/phase" do
64
+ @vanatime.moon_phase.to_s.should == "62% Waxing"
65
+ @vanatime.moon_phase.to_i.should == 62
66
+ end
67
+
68
+ it "should allow reinitializing with a new earth time" do
69
+ vt = VanaTime.new(Time.utc(2007,8,23,12,15,10,10))
70
+ vtsec = vt.to_i
71
+ vanatwo = vt.earth_time=(Time.new)
72
+ vtwosec = vanatwo.to_i
73
+ vtsec.should_not == vtwosec
74
+ end
75
+
76
+ it "should allow reinitializing with a new vana time" do
77
+ reinit = VanaTime.new
78
+ reinit.vana_time = (@vanatime.to_i)
79
+ reinit.earth_time.to_i.should_not == @vanatime.to_i
80
+ end
81
+
82
+ it "should have a constructor using vana time" do
83
+ vt = VanaTime.at(@vanatime.to_i)
84
+ vt.earth_time.to_i.should == @vanatime.earth_time.to_i
85
+ end
86
+ end
data/tasks/rspec.rake ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'spec'
3
+ rescue LoadError
4
+ require 'rubygems'
5
+ require 'spec'
6
+ end
7
+ begin
8
+ require 'spec/rake/spectask'
9
+ rescue LoadError
10
+ puts <<-EOS
11
+ To use rspec for testing you must install rspec gem:
12
+ gem install rspec
13
+ EOS
14
+ exit(0)
15
+ end
16
+
17
+ desc "Run the specs under spec/models"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_opts = ['--options', "spec/spec.opts"]
20
+ t.spec_files = FileList['spec/*_spec.rb']
21
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.4
3
+ specification_version: 1
4
+ name: VanaTime
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.0
7
+ date: 2007-08-22 00:00:00 -04:00
8
+ summary: Vanadiel time object
9
+ require_paths:
10
+ - lib
11
+ email: ttilley@gmail.com
12
+ homepage: http://vanatime.rubyforge.org
13
+ rubyforge_project: vanatime
14
+ description: A library for converting realtime to vanadiel time
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Travis Tilley
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - lib/vana_time.rb
37
+ - spec
38
+ - spec/spec.opts
39
+ - spec/spec_helper.rb
40
+ - spec/vana_time_spec.rb
41
+ - tasks
42
+ - tasks/rspec.rake
43
+ test_files: []
44
+
45
+ rdoc_options:
46
+ - --main
47
+ - README.txt
48
+ extra_rdoc_files:
49
+ - History.txt
50
+ - Manifest.txt
51
+ - README.txt
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ requirements: []
57
+
58
+ dependencies:
59
+ - !ruby/object:Gem::Dependency
60
+ name: hoe
61
+ version_requirement:
62
+ version_requirements: !ruby/object:Gem::Version::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: 1.3.0
67
+ version: