distances 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.idea/.name +1 -0
- data/.idea/distances.iml +134 -0
- data/.idea/encodings.xml +4 -0
- data/.idea/misc.xml +27 -0
- data/.idea/modules.xml +8 -0
- data/.idea/scopes/scope_settings.xml +5 -0
- data/.idea/vcs.xml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +2 -0
- data/distances-0.0.1.gem +0 -0
- data/distances.gemspec +23 -0
- data/lib/distances/version.rb +3 -0
- data/lib/distances.rb +322 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b817fbb854d963a4689ef5f3e12d13f1a2ab43a4
|
4
|
+
data.tar.gz: 6b5ba6f3f545874758d8ab2f19c48d4bbe82c6e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 14d2539b5bea03632baf144efe20111e98c15f15234bee353e195cbd010cab0a5c369cf640c7654aa58f778aad320dac95671d95145d5e54dcc500abc0a1ed6a
|
7
|
+
data.tar.gz: dcb38b83b8a7d4151ff535072571a9ced7d3a4d50e3748a7806d11398f9450d2ea8f5bfe5e5cf90de4383ef0f73bc6f9ef4f2c3b3fd75143206ab9eb6a2afe16
|
data/.gitignore
ADDED
data/.idea/.name
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
distances
|
data/.idea/distances.iml
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="FacetManager">
|
4
|
+
<facet type="gem" name="Ruby Gem">
|
5
|
+
<configuration>
|
6
|
+
<option name="GEM_APP_ROOT_PATH" value="$MODULE_DIR$" />
|
7
|
+
<option name="GEM_APP_TEST_PATH" value="$MODULE_DIR$/test" />
|
8
|
+
<option name="GEM_APP_LIB_PATH" value="$MODULE_DIR$/lib" />
|
9
|
+
</configuration>
|
10
|
+
</facet>
|
11
|
+
</component>
|
12
|
+
<component name="ModuleRunConfigurationManager">
|
13
|
+
<configuration default="false" name="gem install" type="CommandRunConfigurationType" factoryName="Gem Command">
|
14
|
+
<module name="distances" />
|
15
|
+
<COMMAND_RUN_CONFIGURATION NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
16
|
+
<COMMAND_RUN_CONFIGURATION NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
17
|
+
<COMMAND_RUN_CONFIGURATION NAME="SHOULD_USE_SDK" VALUE="false" />
|
18
|
+
<COMMAND_RUN_CONFIGURATION NAME="ALTERN_SDK_NAME" VALUE="" />
|
19
|
+
<COMMAND_RUN_CONFIGURATION NAME="myPassParentEnvs" VALUE="true" />
|
20
|
+
<envs />
|
21
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
22
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
23
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" />
|
24
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
25
|
+
<COMMAND_CONFIG_SETTINGS_ID NAME="GEM_NAME" VALUE="bundler" />
|
26
|
+
<COMMAND_CONFIG_SETTINGS_ID NAME="EXECUTABLE_NAME" VALUE="gem" />
|
27
|
+
<COMMAND_CONFIG_SETTINGS_ID NAME="EXECUTABLE_ARGS" VALUE="install ./distances*.gem" />
|
28
|
+
<COMMAND_CONFIG_SETTINGS_ID NAME="WORKING_DIR" VALUE="install ./distances*.gem" />
|
29
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
30
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
31
|
+
<method />
|
32
|
+
</configuration>
|
33
|
+
<configuration default="false" name="test-metric" type="RubyRunConfigurationType" factoryName="Ruby" temporary="true">
|
34
|
+
<module name="distances" />
|
35
|
+
<RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
36
|
+
<RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/test" />
|
37
|
+
<RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
38
|
+
<RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
39
|
+
<RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
40
|
+
<envs />
|
41
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
42
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
43
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" />
|
44
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
45
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="C:\Users\Gregory\RubymineProjects\distances\test\test-metric.rb" />
|
46
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
|
47
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
48
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
49
|
+
<method />
|
50
|
+
</configuration>
|
51
|
+
<configuration default="false" name="test-metric (1)" type="RubyRunConfigurationType" factoryName="Ruby" temporary="true">
|
52
|
+
<module name="distances" />
|
53
|
+
<RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
54
|
+
<RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/test" />
|
55
|
+
<RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
56
|
+
<RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
57
|
+
<RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
58
|
+
<envs />
|
59
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
60
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
61
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" />
|
62
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
63
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/test/test-metric.rb" />
|
64
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
|
65
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
66
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
67
|
+
<method />
|
68
|
+
</configuration>
|
69
|
+
<configuration default="false" name="test-imperial" type="RubyRunConfigurationType" factoryName="Ruby" temporary="true">
|
70
|
+
<module name="distances" />
|
71
|
+
<RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
72
|
+
<RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/test" />
|
73
|
+
<RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
74
|
+
<RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
75
|
+
<RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
76
|
+
<envs />
|
77
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
78
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
79
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" />
|
80
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
81
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/test/test-imperial.rb" />
|
82
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
|
83
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
84
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
85
|
+
<method />
|
86
|
+
</configuration>
|
87
|
+
<configuration default="false" name="test-astronomical" type="RubyRunConfigurationType" factoryName="Ruby" temporary="true">
|
88
|
+
<module name="distances" />
|
89
|
+
<RUBY_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
90
|
+
<RUBY_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$/test" />
|
91
|
+
<RUBY_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
92
|
+
<RUBY_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
93
|
+
<RUBY_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
94
|
+
<envs />
|
95
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="true" />
|
96
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
97
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" />
|
98
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
99
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="$MODULE_DIR$/test/test-astronomical.rb" />
|
100
|
+
<RUBY_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="" />
|
101
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
102
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
103
|
+
<method />
|
104
|
+
</configuration>
|
105
|
+
<configuration default="false" name="IRB console: distances" type="IrbRunConfigurationType" factoryName="IRB console" temporary="true">
|
106
|
+
<module name="distances" />
|
107
|
+
<IRB_RUN_CONFIG NAME="RUBY_ARGS" VALUE="-e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift)" />
|
108
|
+
<IRB_RUN_CONFIG NAME="WORK DIR" VALUE="$MODULE_DIR$" />
|
109
|
+
<IRB_RUN_CONFIG NAME="SHOULD_USE_SDK" VALUE="false" />
|
110
|
+
<IRB_RUN_CONFIG NAME="ALTERN_SDK_NAME" VALUE="" />
|
111
|
+
<IRB_RUN_CONFIG NAME="myPassParentEnvs" VALUE="true" />
|
112
|
+
<envs />
|
113
|
+
<EXTENSION ID="BundlerRunConfigurationExtension" bundleExecEnabled="false" />
|
114
|
+
<EXTENSION ID="JRubyRunConfigurationExtension" NailgunExecEnabled="false" />
|
115
|
+
<EXTENSION ID="RubyCoverageRunConfigurationExtension" enabled="false" sample_coverage="true" track_test_folders="true" runner="rcov" />
|
116
|
+
<EXTENSION ID="org.jetbrains.plugins.ruby.motion.run.MotionSimulatorRunExtension" />
|
117
|
+
<IRB_RUN_CONFIG NAME="SCRIPT_PATH" VALUE="C:/RailsInstaller/Ruby1.9.3/bin/irb" />
|
118
|
+
<IRB_RUN_CONFIG NAME="SCRIPT_ARGS" VALUE="--prompt simple" />
|
119
|
+
<IRB_RUN_CONFIG NAME="IS_RAILS_CONSOLE" VALUE="false" />
|
120
|
+
<RunnerSettings RunnerId="RubyRunner" />
|
121
|
+
<ConfigurationWrapper RunnerId="RubyRunner" />
|
122
|
+
<method />
|
123
|
+
</configuration>
|
124
|
+
</component>
|
125
|
+
<component name="NewModuleRootManager">
|
126
|
+
<content url="file://$MODULE_DIR$">
|
127
|
+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
|
128
|
+
</content>
|
129
|
+
<orderEntry type="jdk" jdkName="ruby-2.0.0-p598" jdkType="RUBY_SDK" />
|
130
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
131
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v1.8.4, ruby-2.0.0-p598) [gem]" level="application" />
|
132
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.3.2, ruby-2.0.0-p598) [gem]" level="application" />
|
133
|
+
</component>
|
134
|
+
</module>
|
data/.idea/encodings.xml
ADDED
data/.idea/misc.xml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="DaemonCodeAnalyzer">
|
4
|
+
<disable_hints />
|
5
|
+
</component>
|
6
|
+
<component name="DependencyValidationManager">
|
7
|
+
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
8
|
+
</component>
|
9
|
+
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
10
|
+
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
11
|
+
<OptionsSetting value="true" id="Add" />
|
12
|
+
<OptionsSetting value="true" id="Remove" />
|
13
|
+
<OptionsSetting value="true" id="Checkout" />
|
14
|
+
<OptionsSetting value="true" id="Update" />
|
15
|
+
<OptionsSetting value="true" id="Status" />
|
16
|
+
<OptionsSetting value="true" id="Edit" />
|
17
|
+
<ConfirmationsSetting value="0" id="Add" />
|
18
|
+
<ConfirmationsSetting value="0" id="Remove" />
|
19
|
+
</component>
|
20
|
+
<component name="ProjectModuleManager">
|
21
|
+
<modules />
|
22
|
+
</component>
|
23
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="ruby-1.9.3-p545" project-jdk-type="RUBY_SDK" />
|
24
|
+
<component name="RunManager">
|
25
|
+
<list size="0" />
|
26
|
+
</component>
|
27
|
+
</project>
|
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/distances.iml" filepath="$PROJECT_DIR$/.idea/distances.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Gregory H. Halverson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Distances
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'distances'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install distances
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it ( https://github.com/[my-github-username]/distances/fork )
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/distances-0.0.1.gem
ADDED
Binary file
|
data/distances.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'distances/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "distances"
|
8
|
+
spec.version = Distances::VERSION
|
9
|
+
spec.authors = ["Gregory H. Halverson"]
|
10
|
+
spec.email = ["gregory.halverson@gmail.com"]
|
11
|
+
spec.summary = %q{Distances}
|
12
|
+
spec.description = %q{Convert between metric, imperial, and astronomical distances.}
|
13
|
+
spec.homepage = "https://github.com/gregory-halverson/distances"
|
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
|
+
end
|
data/lib/distances.rb
ADDED
@@ -0,0 +1,322 @@
|
|
1
|
+
require "distances/version"
|
2
|
+
|
3
|
+
module Math
|
4
|
+
def self.sigdig(number)
|
5
|
+
Math.log10(number).floor
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Distance
|
10
|
+
attr_reader :distance
|
11
|
+
attr_accessor :mode, :readable
|
12
|
+
|
13
|
+
@@ROUND = 13
|
14
|
+
@@DECIMAL_PLACES = 2
|
15
|
+
@@METERS_TO_FEET = 3.28084
|
16
|
+
@@FEET_TO_METERS = 0.3048
|
17
|
+
@@AU_TO_METERS = 149597870691.0
|
18
|
+
|
19
|
+
def initialize(distance=0, mode=:metric, display=:readable)
|
20
|
+
case mode
|
21
|
+
when :metric
|
22
|
+
self.from_meters distance
|
23
|
+
when :imperial
|
24
|
+
self.from_feet distance
|
25
|
+
when :astronomical
|
26
|
+
self.from_au distance
|
27
|
+
end
|
28
|
+
|
29
|
+
@mode = mode
|
30
|
+
@display = display
|
31
|
+
end
|
32
|
+
|
33
|
+
def from_meters(meters)
|
34
|
+
@distance = meters
|
35
|
+
self
|
36
|
+
end
|
37
|
+
|
38
|
+
def from_feet(feet)
|
39
|
+
from_meters(Distance.feet_to_meters(feet))
|
40
|
+
end
|
41
|
+
|
42
|
+
def from_au(au)
|
43
|
+
from_meters(Distance.au_to_meters(au))
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.meters_to_feet(meters)
|
47
|
+
meters * @@METERS_TO_FEET
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.feet_to_meters(feet)
|
51
|
+
feet * @@FEET_TO_METERS
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.meters_to_au(meters)
|
55
|
+
meters / @@AU_TO_METERS
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.au_to_meters(au)
|
59
|
+
au * @@AU_TO_METERS
|
60
|
+
end
|
61
|
+
|
62
|
+
def meters
|
63
|
+
self.distance
|
64
|
+
end
|
65
|
+
|
66
|
+
def decameters
|
67
|
+
(self.meters / 10.0).round(@@ROUND)
|
68
|
+
end
|
69
|
+
|
70
|
+
def hectometers
|
71
|
+
(self.meters / 100.0).round(@@ROUND)
|
72
|
+
end
|
73
|
+
|
74
|
+
def kilometers
|
75
|
+
(self.meters / 1000.0).round(@@ROUND)
|
76
|
+
end
|
77
|
+
|
78
|
+
def megameters
|
79
|
+
(self.meters / (10.0 ** 6)).round(@@ROUND)
|
80
|
+
end
|
81
|
+
|
82
|
+
def gigameters
|
83
|
+
(self.meters / (10.0 ** 9)).round(@@ROUND)
|
84
|
+
end
|
85
|
+
|
86
|
+
def terameters
|
87
|
+
(self.meters / (10.0 ** 12)).round(@@ROUND)
|
88
|
+
end
|
89
|
+
|
90
|
+
def petameters
|
91
|
+
(self.meters / (10.0 ** 15)).round(@@ROUND)
|
92
|
+
end
|
93
|
+
|
94
|
+
def exameters
|
95
|
+
(self.meters / (10.0 ** 18)).round(@@ROUND)
|
96
|
+
end
|
97
|
+
|
98
|
+
def zettameters
|
99
|
+
(self.meters / (10.0 ** 21)).round(@@ROUND)
|
100
|
+
end
|
101
|
+
|
102
|
+
def yottameters
|
103
|
+
(self.meters / (10.0 ** 24)).round(@@ROUND)
|
104
|
+
end
|
105
|
+
|
106
|
+
def decimeters
|
107
|
+
(self.meters * 10.0).round(@@ROUND)
|
108
|
+
end
|
109
|
+
|
110
|
+
def centimeters
|
111
|
+
(self.meters * 100.0).round(@@ROUND)
|
112
|
+
end
|
113
|
+
|
114
|
+
def millimeters
|
115
|
+
(self.meters * 1000.0).round(@@ROUND)
|
116
|
+
end
|
117
|
+
|
118
|
+
def micrometers
|
119
|
+
(self.meters * (10.0 ** 6)).round(@@ROUND)
|
120
|
+
end
|
121
|
+
|
122
|
+
def nanometers
|
123
|
+
(self.meters * (10.0 ** 9)).round(@@ROUND)
|
124
|
+
end
|
125
|
+
|
126
|
+
def picometers
|
127
|
+
(self.meters * (10.0 ** 12)).round(@@ROUND)
|
128
|
+
end
|
129
|
+
|
130
|
+
def femtometers
|
131
|
+
(self.meters * (10.0 ** 15)).round(@@ROUND)
|
132
|
+
end
|
133
|
+
|
134
|
+
def attometers
|
135
|
+
(self.meters * (10.0 ** 18)).round(@@ROUND)
|
136
|
+
end
|
137
|
+
|
138
|
+
def zeptometers
|
139
|
+
(self.meters * (10.0 ** 21)).round(@@ROUND)
|
140
|
+
end
|
141
|
+
|
142
|
+
def yoctometers
|
143
|
+
(self.meters * (10.0 ** 24)).round(@@ROUND)
|
144
|
+
end
|
145
|
+
|
146
|
+
def feet
|
147
|
+
self.meters * @@METERS_TO_FEET
|
148
|
+
end
|
149
|
+
|
150
|
+
def inches
|
151
|
+
self.feet * 12
|
152
|
+
end
|
153
|
+
|
154
|
+
def thous
|
155
|
+
self.inches * 1000
|
156
|
+
end
|
157
|
+
|
158
|
+
def yards
|
159
|
+
self.feet / 3.0
|
160
|
+
end
|
161
|
+
|
162
|
+
def chains
|
163
|
+
self.feet / 66.0
|
164
|
+
end
|
165
|
+
|
166
|
+
def furlongs
|
167
|
+
self.feet / 660.0
|
168
|
+
end
|
169
|
+
|
170
|
+
def miles
|
171
|
+
self.feet / 5280.0
|
172
|
+
end
|
173
|
+
|
174
|
+
def leagues
|
175
|
+
self.feet / 15840.0
|
176
|
+
end
|
177
|
+
|
178
|
+
def fathoms
|
179
|
+
self.feet / 6.0
|
180
|
+
end
|
181
|
+
|
182
|
+
def cables
|
183
|
+
self.feet / 608.0
|
184
|
+
end
|
185
|
+
|
186
|
+
def nautical_miles
|
187
|
+
self.feet / 6080.0
|
188
|
+
end
|
189
|
+
|
190
|
+
def au
|
191
|
+
self.meters / @@AU_TO_METERS
|
192
|
+
end
|
193
|
+
|
194
|
+
def to_metric
|
195
|
+
new_distance = self.clone
|
196
|
+
new_distance.mode = :metric
|
197
|
+
new_distance
|
198
|
+
end
|
199
|
+
|
200
|
+
def to_imperial
|
201
|
+
new_distance = self.clone
|
202
|
+
new_distance.mode = :imperial
|
203
|
+
new_distance
|
204
|
+
end
|
205
|
+
|
206
|
+
def to_astronomical
|
207
|
+
new_distance = self.clone
|
208
|
+
new_distance.mode = :astronomical
|
209
|
+
new_distance
|
210
|
+
end
|
211
|
+
|
212
|
+
def to_s_metric
|
213
|
+
sigdig = Math.sigdig(self.meters)
|
214
|
+
|
215
|
+
return "#{self.yottameters} Ym" if sigdig >= 24
|
216
|
+
|
217
|
+
return "#{self.yoctometers} ym" if sigdig <= -24
|
218
|
+
|
219
|
+
case sigdig
|
220
|
+
when -23..-21
|
221
|
+
return "#{self.zeptometers.round(@@DECIMAL_PLACES)} zm"
|
222
|
+
when -20..-18
|
223
|
+
return "#{self.attometers.round(@@DECIMAL_PLACES)} am"
|
224
|
+
when -17..-15
|
225
|
+
return "#{self.femtometers.round(@@DECIMAL_PLACES)} fm"
|
226
|
+
when -14..-12
|
227
|
+
return "#{self.picometers.round(@@DECIMAL_PLACES)} pm"
|
228
|
+
when -11..-9
|
229
|
+
return "#{self.nanometers.round(@@DECIMAL_PLACES)} nm"
|
230
|
+
when -8..-6
|
231
|
+
return "#{self.micrometers.round(@@DECIMAL_PLACES)} \u03bcm"
|
232
|
+
when -5..-3
|
233
|
+
return "#{self.millimeters.round(@@DECIMAL_PLACES)} mm"
|
234
|
+
when -2
|
235
|
+
return "#{self.centimeters.round(@@DECIMAL_PLACES)} cm"
|
236
|
+
when -1
|
237
|
+
return "#{self.decimeters.round(@@DECIMAL_PLACES)} dm"
|
238
|
+
when 0
|
239
|
+
return "#{self.meters.round(@@DECIMAL_PLACES)} m"
|
240
|
+
when 1
|
241
|
+
return "#{self.decameters.round(@@DECIMAL_PLACES)} dam"
|
242
|
+
when 2
|
243
|
+
return "#{self.hectometers.round(@@DECIMAL_PLACES)} hm"
|
244
|
+
when 3..5
|
245
|
+
return "#{self.kilometers.round(@@DECIMAL_PLACES)} km"
|
246
|
+
when 6..8
|
247
|
+
return "#{self.megameters.round(@@DECIMAL_PLACES)} Mm"
|
248
|
+
when 9..11
|
249
|
+
return "#{self.gigameters.round(@@DECIMAL_PLACES)} Gm"
|
250
|
+
when 12..14
|
251
|
+
return "#{self.terameters.round(@@DECIMAL_PLACES)} Tm"
|
252
|
+
when 15..17
|
253
|
+
return "#{self.petameters.round(@@DECIMAL_PLACES)} Pm"
|
254
|
+
when 18..20
|
255
|
+
return "#{self.exameters.round(@@DECIMAL_PLACES)} Em"
|
256
|
+
when 21..23
|
257
|
+
return "#{self.zettameters.round(@@DECIMAL_PLACES)} Zm"
|
258
|
+
else
|
259
|
+
return "#{self.meters.round(@@DECIMAL_PLACES)} m"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def to_s_imperial
|
264
|
+
feet = self.feet
|
265
|
+
|
266
|
+
return "#{self.inches.round(@@DECIMAL_PLACES)} in" if feet < 1
|
267
|
+
|
268
|
+
return "#{self.miles.round(@@DECIMAL_PLACES)} mi" if feet >= 5280 / 2
|
269
|
+
|
270
|
+
"#{feet.round(@@DECIMAL_PLACES)} ft"
|
271
|
+
end
|
272
|
+
|
273
|
+
def to_s_astronomical
|
274
|
+
"#{self.au} AU"
|
275
|
+
end
|
276
|
+
|
277
|
+
def to_f
|
278
|
+
case mode
|
279
|
+
when :metric
|
280
|
+
self.meters.to_f
|
281
|
+
when :imperial
|
282
|
+
self.feet.to_f
|
283
|
+
when :astronomical
|
284
|
+
self.au.to_f
|
285
|
+
else
|
286
|
+
self.to_f.to_s
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def to_s
|
291
|
+
case mode
|
292
|
+
when :metric
|
293
|
+
self.to_s_metric
|
294
|
+
when :imperial
|
295
|
+
self.to_s_imperial
|
296
|
+
when :astronomical
|
297
|
+
self.to_s_astronomical
|
298
|
+
else
|
299
|
+
self.to_f.to_s
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
|
304
|
+
def meters(meters)
|
305
|
+
Distance.new meters, mode=:metric
|
306
|
+
end
|
307
|
+
|
308
|
+
def feet(feet)
|
309
|
+
Distance.new feet, mode=:imperial
|
310
|
+
end
|
311
|
+
|
312
|
+
def inches(inches)
|
313
|
+
Distance.new(inches / 12.0, mode=:imperial)
|
314
|
+
end
|
315
|
+
|
316
|
+
def miles(miles)
|
317
|
+
Distance.new(miles * 5280, mode=:imperial)
|
318
|
+
end
|
319
|
+
|
320
|
+
def au(au)
|
321
|
+
Distance.new au, mode=:astronomical
|
322
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: distances
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gregory H. Halverson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-08 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
|
+
description: Convert between metric, imperial, and astronomical distances.
|
42
|
+
email:
|
43
|
+
- gregory.halverson@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .idea/.name
|
50
|
+
- .idea/distances.iml
|
51
|
+
- .idea/encodings.xml
|
52
|
+
- .idea/misc.xml
|
53
|
+
- .idea/modules.xml
|
54
|
+
- .idea/scopes/scope_settings.xml
|
55
|
+
- .idea/vcs.xml
|
56
|
+
- Gemfile
|
57
|
+
- LICENSE.txt
|
58
|
+
- README.md
|
59
|
+
- Rakefile
|
60
|
+
- distances-0.0.1.gem
|
61
|
+
- distances.gemspec
|
62
|
+
- lib/distances.rb
|
63
|
+
- lib/distances/version.rb
|
64
|
+
homepage: https://github.com/gregory-halverson/distances
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.0.15
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: Distances
|
88
|
+
test_files: []
|