quantify-amee 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/CHANGELOG.txt +1 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +19 -0
- data/README.md +31 -0
- data/Rakefile +51 -0
- data/VERSION +1 -0
- data/lib/quantify-amee.rb +143 -0
- data/spec/quantify_amee_spec.rb +85 -0
- metadata +166 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.8.7@quantify-amee
|
data/CHANGELOG.txt
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
= Changelog
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem "quantify", "~> 3.1"
|
4
|
+
|
5
|
+
# Add dependencies to develop your gem here.
|
6
|
+
# Include everything needed to run rake, tests, features, etc.
|
7
|
+
group :development do
|
8
|
+
gem "bundler", "~> 1.0.0"
|
9
|
+
gem "jeweler", "~> 1.6.4"
|
10
|
+
gem 'rspec', '~> 2.6.0'
|
11
|
+
gem 'rcov'
|
12
|
+
gem 'rdoc'
|
13
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012 by Andrew Berkeley (andrew.berkeley.is@googlemail.com)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Quantify-ruby
|
2
|
+
========
|
3
|
+
|
4
|
+
This gem represents an installation of the Quantify gem specifically for use with the AMEE platform.
|
5
|
+
|
6
|
+
Licensed under the MIT license (See LICENSE.txt for details)
|
7
|
+
|
8
|
+
Authors: Andrew Berkeley
|
9
|
+
|
10
|
+
Copyright: Copyright (c) Andrew Berkeley
|
11
|
+
|
12
|
+
Homepage: https://github.com/spatchcock/quantify-amee
|
13
|
+
|
14
|
+
|
15
|
+
Installation
|
16
|
+
------------
|
17
|
+
|
18
|
+
Just include the gem somewhere appropriate.
|
19
|
+
|
20
|
+
|
21
|
+
Requirements
|
22
|
+
------------
|
23
|
+
|
24
|
+
* Quantify > 3.1
|
25
|
+
|
26
|
+
Usage
|
27
|
+
-----
|
28
|
+
|
29
|
+
Simply require 'quantify-amee'. This pulls in the Quantify gem and configures the system of units for use with the AMEE platform. This involves removing units which are not valid for use in AMEE, as well as some appropriate name and symbol changes.
|
30
|
+
|
31
|
+
See https://github.com/spatchcock/quantify for details on the core Quantify gem.
|
data/Rakefile
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
require 'rspec'
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
|
16
|
+
task :default => [:spec]
|
17
|
+
|
18
|
+
desc "Run specs"
|
19
|
+
RSpec::Core::RakeTask.new do |t|
|
20
|
+
# Put spec opts in a file named .rspec in root
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'jeweler'
|
24
|
+
|
25
|
+
Jeweler::Tasks.new do |gem|
|
26
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
27
|
+
gem.name = "quantify-amee"
|
28
|
+
gem.homepage = "https://github.com/spatchcock/quantify-amee"
|
29
|
+
gem.license = "MIT"
|
30
|
+
gem.summary = %Q{Quantify extension which configures units for use with the AMEE platform}
|
31
|
+
gem.description = %Q{Quantify extension which configures units for use with the AMEE platform}
|
32
|
+
gem.email = "andrew.berkeley.is@googlemail.com"
|
33
|
+
gem.authors = ["Andrew Berkeley"]
|
34
|
+
# dependencies defined in Gemfile
|
35
|
+
end
|
36
|
+
Jeweler::RubygemsDotOrgTasks.new
|
37
|
+
|
38
|
+
require 'rcov/rcovtask'
|
39
|
+
desc "Generate code coverage"
|
40
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
41
|
+
t.rcov = true
|
42
|
+
t.rcov_opts = ['--exclude', 'spec']
|
43
|
+
end
|
44
|
+
|
45
|
+
require 'rdoc/task'
|
46
|
+
RDoc::Task.new do |rd|
|
47
|
+
rd.title = "Quantify-AMEE"
|
48
|
+
rd.rdoc_dir = 'doc'
|
49
|
+
rd.main = "README"
|
50
|
+
rd.rdoc_files.include("README", "lib/**/*.rb")
|
51
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,143 @@
|
|
1
|
+
require 'quantify'
|
2
|
+
|
3
|
+
Quantify::Unit.configure do
|
4
|
+
|
5
|
+
# Remove from the system of known units, the units which are not used or not
|
6
|
+
# anticipated to be useful for interacting with AMEE. These either represent
|
7
|
+
# physical quantities which are not typically represented in emissions
|
8
|
+
# calculations (e.g. redioactivity, thermal resistance) or units which do
|
9
|
+
# represent appropriate physical quantities but are relatively obscure or
|
10
|
+
# inappropriate (e.g angstrom, calorie, cup, light year).
|
11
|
+
#
|
12
|
+
# Note: although AMEE supports 8 types of British thermal unit, only one is
|
13
|
+
# made available since it is unlikely that users would like to choose between
|
14
|
+
# each of the alternatives.
|
15
|
+
|
16
|
+
required_units = [ "1",
|
17
|
+
"Hz",
|
18
|
+
"Ohm",
|
19
|
+
"V",
|
20
|
+
"m/s",
|
21
|
+
"m/s²",
|
22
|
+
"A",
|
23
|
+
"K",
|
24
|
+
"m",
|
25
|
+
"mol",
|
26
|
+
"s",
|
27
|
+
"kg",
|
28
|
+
"g",
|
29
|
+
"km",
|
30
|
+
"m³",
|
31
|
+
"J",
|
32
|
+
"N",
|
33
|
+
"W",
|
34
|
+
"Pa",
|
35
|
+
"m²",
|
36
|
+
"atm",
|
37
|
+
"bar",
|
38
|
+
"ha",
|
39
|
+
"L",
|
40
|
+
"bbl",
|
41
|
+
"oz_fl_uk",
|
42
|
+
"gal_uk",
|
43
|
+
"gallon_dry_us",
|
44
|
+
"oz_fl",
|
45
|
+
"bbl_fl_us",
|
46
|
+
"gal",
|
47
|
+
"kWh",
|
48
|
+
"°C",
|
49
|
+
"°F",
|
50
|
+
"°R",
|
51
|
+
"ft",
|
52
|
+
"h",
|
53
|
+
"in",
|
54
|
+
"mi",
|
55
|
+
"min",
|
56
|
+
"month",
|
57
|
+
"nmi",
|
58
|
+
"oz",
|
59
|
+
"lb",
|
60
|
+
"t",
|
61
|
+
"week",
|
62
|
+
"yd",
|
63
|
+
"year",
|
64
|
+
"BTU_FiftyNineF",
|
65
|
+
"ton_us",
|
66
|
+
"ton_uk",
|
67
|
+
"d",
|
68
|
+
"lbmol"]
|
69
|
+
|
70
|
+
uneeded_units = []
|
71
|
+
|
72
|
+
# Determine units which are not required
|
73
|
+
units.each do |unit|
|
74
|
+
uneeded_units << unit.label unless required_units.include?(unit.label)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Unload all unrequired units
|
78
|
+
unload(uneeded_units)
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
Quantify::Unit::SI.configure do
|
83
|
+
|
84
|
+
# Load the commonly used SI unit/prefix combinations which are used in AMEE
|
85
|
+
prefix_and_load [:mega,:giga], :gram
|
86
|
+
prefix_and_load [:mega,:giga,:tera], :joule
|
87
|
+
prefix_and_load [:kilo,:mega], :watt
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
Quantify::Unit::NonSI.configure do
|
92
|
+
|
93
|
+
# Give the remaining (default) British thermal unit version a humanised name
|
94
|
+
# and symbol
|
95
|
+
Unit.BTU_FiftyNineF.configure_as_canonical do |unit|
|
96
|
+
unit.name = 'british thermal unit'
|
97
|
+
unit.symbol = 'BTU'
|
98
|
+
end
|
99
|
+
|
100
|
+
# Differentiate long and short ton symbols
|
101
|
+
Unit.ton_us.configure_as_canonical do |unit|
|
102
|
+
unit.symbol = 'ton (US)'
|
103
|
+
end
|
104
|
+
|
105
|
+
Unit.ton_uk.configure_as_canonical do |unit|
|
106
|
+
unit.symbol = 'ton (UK)'
|
107
|
+
end
|
108
|
+
|
109
|
+
# Differentiate gallon symbols
|
110
|
+
Unit.gal.configure_as_canonical do |unit|
|
111
|
+
unit.symbol = 'gal (US)'
|
112
|
+
end
|
113
|
+
|
114
|
+
Unit.gallon_dry_us.configure_as_canonical do |unit|
|
115
|
+
unit.symbol = 'gal (US dry)'
|
116
|
+
end
|
117
|
+
|
118
|
+
Unit.gal_uk.configure_as_canonical do |unit|
|
119
|
+
unit.symbol = 'gal (UK)'
|
120
|
+
end
|
121
|
+
|
122
|
+
# Differentiate fluid ounce symbols
|
123
|
+
Unit.oz_fl.configure_as_canonical do |unit|
|
124
|
+
unit.symbol = 'fl oz (US)'
|
125
|
+
end
|
126
|
+
|
127
|
+
Unit.oz_fl_uk.configure_as_canonical do |unit|
|
128
|
+
unit.symbol = 'fl oz (UK)'
|
129
|
+
end
|
130
|
+
|
131
|
+
# AMEE uses 'day' rather than 'd' as the label for the time period, day
|
132
|
+
Unit.day.canonical_label = 'day'
|
133
|
+
|
134
|
+
# Load prefixed version of British thermal unit, which is used in AMEE
|
135
|
+
prefix_and_load :M, :BTU_FiftyNineF
|
136
|
+
|
137
|
+
# Define and load the megawatt hour, an energy unit used in AMEE
|
138
|
+
construct_and_load(megawatt*hour) do |unit|
|
139
|
+
unit.symbol = 'MWh'
|
140
|
+
unit.label = 'MWh'
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'quantify-amee'
|
2
|
+
|
3
|
+
describe "AMEE units" do
|
4
|
+
|
5
|
+
include Quantify
|
6
|
+
|
7
|
+
it "should include commonly used SI units" do
|
8
|
+
Unit.metre.should be_loaded
|
9
|
+
Unit.second.should be_loaded
|
10
|
+
Unit.kg.should be_loaded
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should include commonly used non SI units" do
|
14
|
+
Unit.foot.should be_loaded
|
15
|
+
Unit.pound.should be_loaded
|
16
|
+
Unit.month.should be_loaded
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should exclude uncommonly used SI units" do
|
20
|
+
Unit.micrometre.should_not be_loaded
|
21
|
+
lambda{Unit.galileo}.should raise_error
|
22
|
+
lambda{Unit.inverse_centimetre}.should raise_error
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should exclude uncommonly used non SI units" do
|
26
|
+
lambda{Unit.astronomical_unit}.should raise_error
|
27
|
+
lambda{Unit.dyne_centimetre}.should raise_error
|
28
|
+
lambda{Unit.maxwell}.should raise_error
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should include commonly used SI units and prefixes" do
|
32
|
+
Unit.terajoule.should be_loaded
|
33
|
+
Unit.gigagram.should be_loaded
|
34
|
+
Unit.megawatt.should be_loaded
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should include commonly used Non SI units and prefixes" do
|
38
|
+
Unit.MBTU.should be_loaded
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should exclude uncommonly used SI units and prefixes" do
|
42
|
+
Unit.microjoule.should_not be_loaded
|
43
|
+
Unit.nanogram.should_not be_loaded
|
44
|
+
Unit.picowatt.should_not be_loaded
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should represent the BTU with the 59F version" do
|
48
|
+
Unit.BTU.label.should eql "BTU_FiftyNineF"
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should label the unit for 'day' as 'day'" do
|
52
|
+
Unit.day.label.should eql 'day'
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should recognise the unit for megawatt_hour as 'MWh'" do
|
56
|
+
Unit.megawatt_hour.label.should eql 'MWh'
|
57
|
+
Unit.megawatt_hour.symbol.should eql 'MWh'
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should use the correct symbol for a US ton" do
|
61
|
+
Unit.ton_us.symbol.should eql 'ton (US)'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should use the correct symbol for a UK ton" do
|
65
|
+
Unit.ton_uk.symbol.should eql 'ton (UK)'
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should use the correct symbol for a US gallon" do
|
69
|
+
Unit.gal.symbol.should eql 'gal (US)'
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should use the correct symbol for a US dry gallon" do
|
73
|
+
Unit.gallon_dry_us.symbol.should eql 'gal (US dry)'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should use the correct symbol for a UK gallon" do
|
77
|
+
Unit.gal_uk.symbol.should eql 'gal (UK)'
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should use the correct symbol for a US ton" do
|
81
|
+
Unit.oz_fl.symbol.should eql 'fl oz (US)'
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
metadata
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quantify-amee
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Andrew Berkeley
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-11 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: quantify
|
23
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 5
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 1
|
32
|
+
version: "3.1"
|
33
|
+
prerelease: false
|
34
|
+
type: :runtime
|
35
|
+
requirement: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 23
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 0
|
47
|
+
- 0
|
48
|
+
version: 1.0.0
|
49
|
+
prerelease: false
|
50
|
+
type: :development
|
51
|
+
requirement: *id002
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: jeweler
|
54
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 7
|
60
|
+
segments:
|
61
|
+
- 1
|
62
|
+
- 6
|
63
|
+
- 4
|
64
|
+
version: 1.6.4
|
65
|
+
prerelease: false
|
66
|
+
type: :development
|
67
|
+
requirement: *id003
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: rspec
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
71
|
+
none: false
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
hash: 23
|
76
|
+
segments:
|
77
|
+
- 2
|
78
|
+
- 6
|
79
|
+
- 0
|
80
|
+
version: 2.6.0
|
81
|
+
prerelease: false
|
82
|
+
type: :development
|
83
|
+
requirement: *id004
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rcov
|
86
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
prerelease: false
|
96
|
+
type: :development
|
97
|
+
requirement: *id005
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rdoc
|
100
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
106
|
+
segments:
|
107
|
+
- 0
|
108
|
+
version: "0"
|
109
|
+
prerelease: false
|
110
|
+
type: :development
|
111
|
+
requirement: *id006
|
112
|
+
description: Quantify extension which configures units for use with the AMEE platform
|
113
|
+
email: andrew.berkeley.is@googlemail.com
|
114
|
+
executables: []
|
115
|
+
|
116
|
+
extensions: []
|
117
|
+
|
118
|
+
extra_rdoc_files:
|
119
|
+
- LICENSE.txt
|
120
|
+
- README.md
|
121
|
+
files:
|
122
|
+
- .rvmrc
|
123
|
+
- CHANGELOG.txt
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- VERSION
|
129
|
+
- lib/quantify-amee.rb
|
130
|
+
- spec/quantify_amee_spec.rb
|
131
|
+
has_rdoc: true
|
132
|
+
homepage: https://github.com/spatchcock/quantify-amee
|
133
|
+
licenses:
|
134
|
+
- MIT
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
|
138
|
+
require_paths:
|
139
|
+
- lib
|
140
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 3
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
version: "0"
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
none: false
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
hash: 3
|
155
|
+
segments:
|
156
|
+
- 0
|
157
|
+
version: "0"
|
158
|
+
requirements: []
|
159
|
+
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 1.5.3
|
162
|
+
signing_key:
|
163
|
+
specification_version: 3
|
164
|
+
summary: Quantify extension which configures units for use with the AMEE platform
|
165
|
+
test_files: []
|
166
|
+
|