Skip to content

Commit ea778e1

Browse files
committed
files added
1 parent 7e39053 commit ea778e1

File tree

11 files changed

+404
-1
lines changed

11 files changed

+404
-1
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
*.gem
2+
*.rbc
3+
.bundle
4+
.config
5+
.yardoc
6+
InstalledFiles
7+
_yardoc
8+
coverage
9+
pkg
10+
rdoc
11+
tags
12+
tmp

.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--format progress

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org'
2+
3+
gemspec

LICENSE.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Copyright (c) 2015 Mateus Maso
2+
3+
Permission is hereby granted, free of charge, to any person
4+
obtaining a copy of this software and associated documentation
5+
files (the "Software"), to deal in the Software without
6+
restriction, including without limitation the rights to use,
7+
copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the
9+
Software is furnished to do so, subject to the following
10+
conditions:
11+
12+
The above copyright notice and this permission notice shall be
13+
included in all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# suncalc-ruby
2-
Ruby port of https://github.com/mourner/suncalc via ExecJS
2+
Ruby port of SunCalc via ExecJS

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require "bundler/gem_tasks"

lib/suncalc.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require "suncalc/version"
2+
require "pathname"
3+
require "execjs"
4+
5+
module SunCalc
6+
def self.source
7+
"window = {}; #{File.read(Pathname(__FILE__).dirname.join('..', 'vendor', 'assets', 'javascripts', 'suncalc.js'))}"
8+
end
9+
10+
def self.context
11+
ExecJS.compile(source)
12+
end
13+
14+
def self.times(date, latitude, longitude)
15+
times = self.context.eval("window.SunCalc.getTimes(new Date(#{date.to_f * 1000}), #{latitude}, #{longitude})")
16+
17+
times.keys.each do |key|
18+
old_key = key
19+
key = key.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
20+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
21+
tr('-', '_').
22+
gsub(/\s/, '_').
23+
gsub(/__+/, '_').
24+
downcase.
25+
to_sym
26+
27+
times[key] = times.delete(old_key)
28+
end
29+
30+
times
31+
end
32+
end

lib/suncalc/version.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module SunCalc
2+
VERSION = "0.0.1"
3+
end

spec/spec_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
RSpec.configure do |config|
2+
config.treat_symbols_as_metadata_keys_with_true_values = true
3+
config.run_all_when_everything_filtered = true
4+
config.filter_run :focus
5+
config.order = 'random'
6+
end

suncalc-ruby.gemspec

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
$:.push File.expand_path("../lib", __FILE__)
2+
require 'suncalc/version'
3+
4+
Gem::Specification.new do |spec|
5+
spec.name = "suncalc-ruby"
6+
spec.version = SunCalc::VERSION
7+
spec.authors = ["mateusmaso"]
8+
spec.email = ["[email protected]"]
9+
spec.description = %q{Ruby port of SunCalc via ExecJS}
10+
spec.summary = %q{Ruby port of SunCalc via ExecJS}
11+
spec.homepage = "https://github.com/mateusmaso/suncalc-ruby"
12+
spec.license = "MIT"
13+
14+
spec.files = `git ls-files`.split($/)
15+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17+
spec.require_paths = ["lib"]
18+
19+
spec.add_dependency 'execjs', ">= 1.3"
20+
end

0 commit comments

Comments
 (0)