astronomy 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +93 -0
- data/Rakefile +11 -0
- data/assets/astronomy.yml +6126 -0
- data/astronomy.gemspec +24 -0
- data/lib/astronomy.rb +36 -0
- data/lib/astronomy/version.rb +3 -0
- data/spec/lib/astronomy_spec.rb +102 -0
- data/spec/spec_helper.rb +1 -0
- metadata +105 -0
data/astronomy.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'astronomy/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'astronomy'
|
8
|
+
spec.version = Astronomy::VERSION
|
9
|
+
spec.authors = ['Nick Aschenbach']
|
10
|
+
spec.email = ['nick.aschenbach@gmail.com']
|
11
|
+
spec.summary = %q{Get information using a simple interface about various celestial phenomena from Freebase. Search or browse the data.}
|
12
|
+
spec.description = %q{Get the names, descriptions and image URLs for various categories including: Asterisms, Celestial Objects, Stars, Planets, Star Systems, Celestial object with coordinate systems, Asteroid Groups, Galaxies, Bodies with heliocentric orbits, Moons, Comets, Asteroids, Constellations, Nebulae, Natural satellites, Astronomical Discoveries, Galactic superclusters, Globular clusters, Supernovae, Galactic filaments, Meteor Showers. Also provides links to the full Freebase JSON data.}
|
13
|
+
spec.homepage = 'https://github.com/nick-aschenbach/astronomy'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
24
|
+
end
|
data/lib/astronomy.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'astronomy/version'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Astronomy
|
5
|
+
class Information
|
6
|
+
DATA_FILE = File.join(File.dirname(__dir__), 'assets', 'astronomy.yml')
|
7
|
+
|
8
|
+
attr_reader :data
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@data = YAML.load_file(DATA_FILE)
|
12
|
+
end
|
13
|
+
|
14
|
+
def categories
|
15
|
+
@data.keys
|
16
|
+
end
|
17
|
+
|
18
|
+
def topics(category)
|
19
|
+
@data[category]
|
20
|
+
end
|
21
|
+
|
22
|
+
def search(topic)
|
23
|
+
query = topic.downcase
|
24
|
+
results = []
|
25
|
+
|
26
|
+
@data.each do |category, array_of_topics|
|
27
|
+
array_of_topics.each do |topic|
|
28
|
+
results << topic and next if topic['name'].downcase.include?(query)
|
29
|
+
results << topic if topic['description'].downcase.include?(query)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
results
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Astronomy::Information do
|
4
|
+
subject { Astronomy::Information.new }
|
5
|
+
|
6
|
+
it 'assigns Astronomy::Data::DATA_FILE' do
|
7
|
+
expect(Astronomy::Information::DATA_FILE).to_not be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '.initialize' do
|
11
|
+
it 'loads the astronomical yaml data' do
|
12
|
+
expect(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE)
|
13
|
+
|
14
|
+
subject
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'stores this data in an instance variable' do
|
18
|
+
data = {foo: 'bar'}
|
19
|
+
allow(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE).and_return(data)
|
20
|
+
expect(subject.instance_variable_get('@data')).to eq(data)
|
21
|
+
|
22
|
+
subject
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#data' do
|
27
|
+
it 'returns what is stored in the instance variable' do
|
28
|
+
data = {bar: 'baz'}
|
29
|
+
allow(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE).and_return(data)
|
30
|
+
|
31
|
+
|
32
|
+
expect(subject.data).to eq(data)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'does not allow re-assignment of the astronomical data' do
|
36
|
+
allow(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE).and_return({bar: 'baz'})
|
37
|
+
|
38
|
+
expect { subject.data = 'foobar' }.to raise_error(NoMethodError)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#categories' do
|
43
|
+
let(:data) { {'Asterism' => [], 'Galaxy' => []} }
|
44
|
+
|
45
|
+
it 'returns a list of top level categories' do
|
46
|
+
allow(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE).and_return(data)
|
47
|
+
|
48
|
+
expect(subject.categories).to match_array(['Asterism', 'Galaxy'])
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#topics' do
|
53
|
+
let(:data) { {'Topic A' => [1, 2, 3], 'Topic B' => %w[a b c]} }
|
54
|
+
|
55
|
+
it 'returns the topics for a specific category' do
|
56
|
+
allow(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE).and_return(data)
|
57
|
+
|
58
|
+
expect(subject.topics('Topic A')).to match_array([1, 2, 3])
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns nil when a category is invalid' do
|
62
|
+
allow(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE).and_return(data)
|
63
|
+
|
64
|
+
expect(subject.topics('Invalid topic')).to be_nil
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#search' do
|
69
|
+
let(:data) { {
|
70
|
+
'Asterism' =>
|
71
|
+
[{'name' => 'Apple', 'description' => 'A lovely fruit'},
|
72
|
+
{'name' => 'Squash', 'description' => 'A great sport or fruit'},
|
73
|
+
{'name' => 'Squish', 'description' => 'A soft wet sound'}]
|
74
|
+
} }
|
75
|
+
|
76
|
+
it 'returns an array of topics with names that match the query' do
|
77
|
+
allow(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE).and_return(data)
|
78
|
+
|
79
|
+
expect(subject.search('sq')).to match_array([{'name' => 'Squash', 'description' => 'A great sport or fruit'},
|
80
|
+
{'name' => 'Squish', 'description' => 'A soft wet sound'}])
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'returns an array of topics with descriptions that match the query' do
|
84
|
+
allow(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE).and_return(data)
|
85
|
+
|
86
|
+
expect(subject.search('fruit')).to match_array([{'name' => 'Apple', 'description' => 'A lovely fruit'},
|
87
|
+
{'name' => 'Squash', 'description' => 'A great sport or fruit'}])
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'returns a topic once when both the name and description match' do
|
91
|
+
allow(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE).and_return(data)
|
92
|
+
|
93
|
+
expect(subject.search('A')).to match_array(data['Asterism'])
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'returns an empty array when the query does not match anything' do
|
97
|
+
allow(YAML).to receive(:load_file).with(Astronomy::Information::DATA_FILE).and_return(data)
|
98
|
+
|
99
|
+
expect(subject.search('zx')).to match_array([])
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'astronomy'
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: astronomy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nick Aschenbach
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: 'Get the names, descriptions and image URLs for various categories including:
|
56
|
+
Asterisms, Celestial Objects, Stars, Planets, Star Systems, Celestial object with
|
57
|
+
coordinate systems, Asteroid Groups, Galaxies, Bodies with heliocentric orbits,
|
58
|
+
Moons, Comets, Asteroids, Constellations, Nebulae, Natural satellites, Astronomical
|
59
|
+
Discoveries, Galactic superclusters, Globular clusters, Supernovae, Galactic filaments,
|
60
|
+
Meteor Showers. Also provides links to the full Freebase JSON data.'
|
61
|
+
email:
|
62
|
+
- nick.aschenbach@gmail.com
|
63
|
+
executables: []
|
64
|
+
extensions: []
|
65
|
+
extra_rdoc_files: []
|
66
|
+
files:
|
67
|
+
- ".gitignore"
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- assets/astronomy.yml
|
73
|
+
- astronomy.gemspec
|
74
|
+
- lib/astronomy.rb
|
75
|
+
- lib/astronomy/version.rb
|
76
|
+
- spec/lib/astronomy_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
homepage: https://github.com/nick-aschenbach/astronomy
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.4.5
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Get information using a simple interface about various celestial phenomena
|
102
|
+
from Freebase. Search or browse the data.
|
103
|
+
test_files:
|
104
|
+
- spec/lib/astronomy_spec.rb
|
105
|
+
- spec/spec_helper.rb
|