Skip to content

Commit 8380291

Browse files
committed
Initial project layout
0 parents  commit 8380291

22 files changed

+278
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
spec/examples.txt
2+
tmp
3+
lib/h3_ruby/*.bundle
4+
lib/h3_ruby/*.so

.rspec

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--require spec_helper

.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.4.4

Gemfile

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
source "https://rubygems.org"
2+
3+
ruby "2.4.4" # Ideally, the same one as stuart-api.
4+
5+
gem "rake-compiler", "~> 1.0.5"
6+
gem "rspec", "~> 3.8.0"

Gemfile.lock

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
diff-lcs (1.3)
5+
geocoder (1.5.0)
6+
rake (12.3.2)
7+
rake-compiler (1.0.5)
8+
rake
9+
rspec (3.8.0)
10+
rspec-core (~> 3.8.0)
11+
rspec-expectations (~> 3.8.0)
12+
rspec-mocks (~> 3.8.0)
13+
rspec-core (3.8.0)
14+
rspec-support (~> 3.8.0)
15+
rspec-expectations (3.8.2)
16+
diff-lcs (>= 1.2.0, < 2.0)
17+
rspec-support (~> 3.8.0)
18+
rspec-mocks (3.8.0)
19+
diff-lcs (>= 1.2.0, < 2.0)
20+
rspec-support (~> 3.8.0)
21+
rspec-support (3.8.0)
22+
23+
PLATFORMS
24+
ruby
25+
26+
DEPENDENCIES
27+
geocoder (~> 1.5.0)
28+
rake-compiler (~> 1.0.5)
29+
rspec (~> 3.8.0)
30+
31+
RUBY VERSION
32+
ruby 2.4.4p296
33+
34+
BUNDLED WITH
35+
1.17.1

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# H3 Ruby
2+
3+
Ruby bindings for Uber's [H3 library](https://uber.github.io/h3/).
4+
5+
TODO: Include h3/h3api.h and add wrapper functions

Rakefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "rake/extensiontask"
2+
3+
Rake::ExtensionTask.new("h3") do |ext|
4+
ext.lib_dir = "lib/h3_ruby"
5+
end

bin/compile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
# With --silent, compilation is silent when there is nothing to do, otherwise
4+
# you'll see stuff happening, and of course errors if there are any.
5+
bundle exec rake compile --silent

bin/console

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
if bin/compile;
4+
then
5+
bundle exec irb -Ilib -rh3_ruby "$@"
6+
fi

bin/rspec

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
if bin/compile;
4+
then
5+
bundle exec rspec "$@"
6+
fi

bin/run

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
if bin/compile;
4+
then
5+
bundle exec ruby -Ilib -rh3_ruby "$@"
6+
fi

ext/.DS_Store

6 KB
Binary file not shown.

ext/h3/extconf.rb

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "mkmf"
2+
create_makefile "h3/h3"

ext/h3/h3.c

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include <ruby.h>
2+
// #include <h3/h3api.h>
3+
4+
static VALUE hello_world(VALUE mod)
5+
{
6+
return rb_str_new2("hello world");
7+
}
8+
9+
/* --- Initialization -------------------------------------------------------------------------- */
10+
11+
/* This function has a special name and it is invoked by Ruby to initialize the extension. */
12+
void Init_h3()
13+
{
14+
VALUE h3_ruby = rb_define_module("H3Ruby");
15+
rb_define_singleton_method(h3_ruby, "hello_world", hello_world, 0);
16+
}

ext/h3/lib/libh3.a

112 KB
Binary file not shown.

h3_ruby.gemspec

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
$: << File.expand_path("lib", __dir__)
2+
require "h3_ruby/version"
3+
4+
Gem::Specification.new do |spec|
5+
spec.name = "h3-ruby"
6+
spec.version = H3Ruby::VERSION
7+
spec.licenses = ["Nonstandard"] # Avoids a warning when building the gem.
8+
spec.summary = "C Bindings for Uber's H3 library"
9+
spec.homepage = "https://github.com/StuartApp/h3_ruby"
10+
spec.author = "Lachlan Laycock"
11+
spec.email = "l.laycock@stuart.com"
12+
13+
spec.extensions = %w(ext/h3/extconf.rb)
14+
spec.require_paths = %w(lib)
15+
spec.files = %w(
16+
ext/h3/extconf.rb
17+
ext/h3/h3.c
18+
lib/h3_ruby.rb
19+
lib/h3_ruby/version.rb
20+
)
21+
end

lib/h3_ruby.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require "h3_ruby/h3"
2+
require "h3_ruby/version"
3+
4+
module H3Ruby
5+
def self.bearing_between(from, to, options={})
6+
_bearing_between(from, to, options[:method] == :spherical)
7+
end
8+
end

lib/h3_ruby/version.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module H3Ruby
2+
VERSION = "0.0.1"
3+
end

spec/h3_ruby_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require "bigdecimal"
2+
3+
RSpec.describe H3Ruby do
4+
describe ".hello_world" do
5+
subject(:hello_world) { H3Ruby.hello_world }
6+
7+
let(:result) { "hello world" }
8+
9+
it "returns the expected result" do
10+
expect(hello_world).to eq(result)
11+
end
12+
end
13+
end

spec/spec_helper.rb

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
require "h3_ruby"
2+
3+
require_relative "support/models"
4+
require_relative "support/matchers"
5+
6+
# This file was generated by the `rspec --init` command. Conventionally, all
7+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
8+
# The generated `.rspec` file contains `--require spec_helper` which will cause
9+
# this file to always be loaded, without a need to explicitly require it in any
10+
# files.
11+
#
12+
# Given that it is always loaded, you are encouraged to keep this file as
13+
# light-weight as possible. Requiring heavyweight dependencies from this file
14+
# will add to the boot time of your test suite on EVERY test run, even for an
15+
# individual file that may not need all of that loaded. Instead, consider making
16+
# a separate helper file that requires the additional dependencies and performs
17+
# the additional setup, and require it from the spec files that actually need
18+
# it.
19+
#
20+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21+
RSpec.configure do |config|
22+
# rspec-expectations config goes here. You can use an alternate
23+
# assertion/expectation library such as wrong or the stdlib/minitest
24+
# assertions if you prefer.
25+
config.expect_with :rspec do |expectations|
26+
# This option will default to `true` in RSpec 4. It makes the `description`
27+
# and `failure_message` of custom matchers include text for helper methods
28+
# defined using `chain`, e.g.:
29+
# be_bigger_than(2).and_smaller_than(4).description
30+
# # => "be bigger than 2 and smaller than 4"
31+
# ...rather than:
32+
# # => "be bigger than 2"
33+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34+
end
35+
36+
# rspec-mocks config goes here. You can use an alternate test double
37+
# library (such as bogus or mocha) by changing the `mock_with` option here.
38+
config.mock_with :rspec do |mocks|
39+
# Prevents you from mocking or stubbing a method that does not exist on
40+
# a real object. This is generally recommended, and will default to
41+
# `true` in RSpec 4.
42+
mocks.verify_partial_doubles = true
43+
end
44+
45+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
46+
# have no way to turn it off -- the option exists only for backwards
47+
# compatibility in RSpec 3). It causes shared context metadata to be
48+
# inherited by the metadata hash of host groups and examples, rather than
49+
# triggering implicit auto-inclusion in groups with matching metadata.
50+
config.shared_context_metadata_behavior = :apply_to_host_groups
51+
52+
# This allows you to limit a spec run to individual examples or groups
53+
# you care about by tagging them with `:focus` metadata. When nothing
54+
# is tagged with `:focus`, all examples get run. RSpec also provides
55+
# aliases for `it`, `describe`, and `context` that include `:focus`
56+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
57+
config.filter_run_when_matching :focus
58+
59+
# Allows RSpec to persist some state between runs in order to support
60+
# the `--only-failures` and `--next-failure` CLI options. We recommend
61+
# you configure your source control system to ignore this file.
62+
config.example_status_persistence_file_path = "spec/examples.txt"
63+
64+
# Limits the available syntax to the non-monkey patched syntax that is
65+
# recommended. For more details, see:
66+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
67+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
68+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
69+
config.disable_monkey_patching!
70+
71+
# This setting enables warnings. It's recommended, but in some cases may
72+
# be too noisy due to issues in dependencies.
73+
# config.warnings = true
74+
75+
# Many RSpec users commonly either run the entire suite or an individual
76+
# file, and it's useful to allow more verbose output when running an
77+
# individual spec file.
78+
# if config.files_to_run.one?
79+
# # Use the documentation formatter for detailed output,
80+
# # unless a formatter has already been configured
81+
# # (e.g. via a command-line flag).
82+
# config.default_formatter = "doc"
83+
# end
84+
85+
# Print the 10 slowest examples and example groups at the
86+
# end of the spec run, to help surface which specs are running
87+
# particularly slow.
88+
# config.profile_examples = 10
89+
90+
# Run specs in random order to surface order dependencies. If you find an
91+
# order dependency and want to debug it, you can fix the order by providing
92+
# the seed, which is printed after each run.
93+
# --seed 1234
94+
config.order = :random
95+
96+
# Seed global randomization in this process using the `--seed` CLI option.
97+
# Setting this allows you to use `--seed` to deterministically reproduce
98+
# test failures related to randomization by passing the same `--seed` value
99+
# as the one that triggered the failure.
100+
Kernel.srand config.seed
101+
end

spec/support/matchers.rb

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
require "rspec/expectations"
2+
3+
RSpec::Matchers.define :approx do |expected|
4+
delta = 1e-11
5+
6+
match do |actual|
7+
case actual
8+
when Array
9+
actual.zip(expected).each do |a, e|
10+
expect(a).to approx(e)
11+
end
12+
else
13+
expect(actual).to be_within(delta).of(expected)
14+
end
15+
end
16+
end

spec/support/models.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Location
2+
attr_reader :lat, :lon
3+
4+
def initialize(lat, lon)
5+
@lat = lat
6+
@lon = lon
7+
end
8+
9+
def to_coordinates
10+
[@lat, @lon]
11+
end
12+
13+
def to_radians
14+
to_coordinates.map do |degrees|
15+
degrees*Math::PI/180.0
16+
end
17+
end
18+
end

0 commit comments

Comments
 (0)