amee-data-abstraction 1.3.1 → 2.0.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.
Files changed (39) hide show
  1. data/.rvmrc +1 -1
  2. data/CHANGELOG.txt +0 -3
  3. data/Gemfile +5 -7
  4. data/Gemfile.lock +20 -14
  5. data/README.txt +15 -28
  6. data/Rakefile +17 -16
  7. data/VERSION +1 -1
  8. data/amee-data-abstraction.gemspec +21 -24
  9. data/lib/amee-data-abstraction.rb +6 -0
  10. data/lib/amee-data-abstraction/calculation.rb +1 -1
  11. data/lib/amee-data-abstraction/calculation_set.rb +10 -152
  12. data/lib/amee-data-abstraction/drill.rb +6 -23
  13. data/lib/amee-data-abstraction/input.rb +0 -24
  14. data/lib/amee-data-abstraction/ongoing_calculation.rb +9 -13
  15. data/lib/amee-data-abstraction/term.rb +13 -31
  16. data/spec/amee-data-abstraction/calculation_set_spec.rb +11 -245
  17. data/spec/amee-data-abstraction/calculation_spec.rb +18 -23
  18. data/spec/amee-data-abstraction/drill_spec.rb +7 -34
  19. data/spec/amee-data-abstraction/input_spec.rb +73 -113
  20. data/spec/amee-data-abstraction/metadatum_spec.rb +1 -1
  21. data/spec/amee-data-abstraction/ongoing_calculation_spec.rb +29 -45
  22. data/spec/amee-data-abstraction/profile_spec.rb +2 -2
  23. data/spec/amee-data-abstraction/prototype_calculation_spec.rb +11 -18
  24. data/spec/amee-data-abstraction/term_spec.rb +8 -50
  25. data/spec/amee-data-abstraction/terms_list_spec.rb +12 -16
  26. data/spec/config/amee_units_spec.rb +2 -1
  27. data/spec/core-extensions/class_spec.rb +18 -18
  28. data/spec/core-extensions/hash_spec.rb +2 -1
  29. data/spec/core-extensions/ordered_hash_spec.rb +2 -1
  30. data/spec/core-extensions/proc_spec.rb +1 -1
  31. data/spec/fixtures/{config/electricity.rb → electricity.rb} +2 -2
  32. data/spec/fixtures/electricity_and_transport.rb +55 -0
  33. data/spec/fixtures/{config/calculations/transport.rb → transport.rb} +2 -2
  34. data/spec/spec_helper.rb +7 -43
  35. metadata +56 -61
  36. data/init.rb +0 -4
  37. data/rails/init.rb +0 -32
  38. data/spec/fixtures/config/calculations/electricity.rb +0 -35
  39. data/spec/fixtures/config/calculations/electricity_and_transport.rb +0 -53
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.8.7@amee-data-abstraction-rails2
1
+ rvm 1.8.7@amee-data-abstraction
data/CHANGELOG.txt CHANGED
@@ -1,7 +1,4 @@
1
1
  = Changelog
2
2
 
3
- == 1.3.0
4
- * Reconfigure storage and API for Calculation Sets
5
-
6
3
  == 1.0.0
7
4
  * Initial public release
data/Gemfile CHANGED
@@ -1,16 +1,14 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "amee", "~> 3.1"
3
+ gem "amee", "~> 4.0"
4
4
  gem 'uuidtools', '2.1.2'
5
- gem 'quantify', '1.2.2'
5
+ gem 'quantify', '~> 2.0.0'
6
6
 
7
- # Add dependencies to develop your gem here.
8
- # Include everything needed to run rake, tests, features, etc.
9
7
  group :development do
10
8
  gem "bundler", "~> 1.0.0"
11
9
  gem "jeweler", "~> 1.6.4"
12
- gem 'rspec', '1.3.0'
13
- gem 'rcov'
14
- gem 'rspec_spinner', '1.1.3'
10
+ gem 'rspec', '2.6.0'
15
11
  gem 'flexmock', '> 0.8.6'
12
+ gem 'rcov'
13
+ gem 'rdoc'
16
14
  end
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- activesupport (2.3.12)
5
- amee (3.1.2)
6
- activesupport (~> 2.3.5)
4
+ activesupport (3.0.10)
5
+ amee (4.0.0)
6
+ activesupport (~> 3.0.10)
7
7
  json
8
8
  log4r
9
9
  nokogiri (~> 1.4.3.1)
10
+ diff-lcs (1.1.3)
10
11
  flexmock (0.9.0)
11
12
  git (1.2.5)
12
13
  i18n (0.6.0)
@@ -14,30 +15,35 @@ GEM
14
15
  bundler (~> 1.0)
15
16
  git (>= 1.2.5)
16
17
  rake
17
- json (1.6.1)
18
+ json (1.5.4)
18
19
  log4r (1.1.9)
19
20
  nokogiri (1.4.3.1)
20
- quantify (1.2.2)
21
- activesupport
21
+ quantify (2.0.0)
22
+ activesupport (~> 3.0.10)
22
23
  i18n
23
24
  rake (0.9.2)
24
25
  rcov (0.9.10)
25
- rspec (1.3.0)
26
- rspec_spinner (1.1.3)
27
- rtui
28
- rtui (0.2.2)
26
+ rdoc (3.9.4)
27
+ rspec (2.6.0)
28
+ rspec-core (~> 2.6.0)
29
+ rspec-expectations (~> 2.6.0)
30
+ rspec-mocks (~> 2.6.0)
31
+ rspec-core (2.6.4)
32
+ rspec-expectations (2.6.0)
33
+ diff-lcs (~> 1.1.2)
34
+ rspec-mocks (2.6.0)
29
35
  uuidtools (2.1.2)
30
36
 
31
37
  PLATFORMS
32
38
  ruby
33
39
 
34
40
  DEPENDENCIES
35
- amee (~> 3.1)
41
+ amee (~> 4.0)
36
42
  bundler (~> 1.0.0)
37
43
  flexmock (> 0.8.6)
38
44
  jeweler (~> 1.6.4)
39
- quantify (= 1.2.2)
45
+ quantify (~> 2.0.0)
40
46
  rcov
41
- rspec (= 1.3.0)
42
- rspec_spinner (= 1.1.3)
47
+ rdoc
48
+ rspec (= 2.6.0)
43
49
  uuidtools (= 2.1.2)
data/README.txt CHANGED
@@ -25,9 +25,9 @@ Documentation: http://rubydoc.info/gems/amee-data-abstraction
25
25
  All gem requirements should be installed as part of the rubygems installation process
26
26
  above, but are listed here for completeness.
27
27
 
28
- * amee ~> 3.1
28
+ * amee ~> 3.0
29
29
  * uuidtools = 2.1.2
30
- * quantify = 1.2.2
30
+ * quantify = 1.1.0
31
31
 
32
32
  == USAGE
33
33
 
@@ -117,10 +117,16 @@ Submit to AMEE for calculation
117
117
 
118
118
  Typical practice is initialize the calculation prototypes required for an
119
119
  application via a configuration file which creates the required calculation
120
- templates within an instance of CalculationSet. Such a configuration file can
121
- be structured the follow DSL:
120
+ templates within an instance of CalculationSet. If the calculation set is assigned
121
+ to a global variable or constant, the set of prototypes is available for
122
+ initializing new calculations and templating view structures (e.g. tables, forms)
123
+ from anywhere in the application.
122
124
 
123
- # e.g. /config/calculations/my_emissions_calculations.rb
125
+ Adding a configuration to /config or /config/initializers may be appropriate
126
+
127
+ # e.g. /config/initializers/calculations.rb
128
+
129
+ Calculations = AMEE::DataAbstraction::CalculationSet {
124
130
 
125
131
  calculation {
126
132
  label :electricity
@@ -142,36 +148,17 @@ be structured the follow DSL:
142
148
  path "/some/fuel/associated/path/in/amee"
143
149
  terms_from_amee
144
150
  }
145
-
146
- The default location for such files within Rails applications is under
147
- /config/calculations. If such an approach is taken, the configuration can be
148
- read and a calculation set generated by using the filename, thus:
149
-
150
- CalculationSet.find('my_emissions_calculations')
151
-
152
- #=> <AMEE::DataAbstraction::CalculationSet ... >
153
-
154
- Otherwise, the path to the configuration file can be provided:
155
-
156
- CalculationSet.find('some/directory/my_emissions_calculations')
157
-
158
- #=> <AMEE::DataAbstraction::CalculationSet ... >
159
-
160
- The calculation set is accessible as follow using the same argument as used
161
- by the Find method (filename if conventional Rails location, path otherwise):
162
-
163
- CalculationSet.sets['my_emissions_calculations']
151
+ }
164
152
 
165
153
  #=> <AMEE::DataAbstraction::CalculationSet ... >
166
154
 
167
- And a new calcualtion can be initialized by providing the prototype calculation
168
- label:
155
+ From this global calculation set, initialize a new calculation
169
156
 
170
- my_fuel_calculation = CalculationSet.sets['my_emissions_calcualtions'][:fuel].begin_calculation
157
+ my_fuel_calculation = Calculations[:fuel].begin_calculation
171
158
 
172
159
  #=> <AMEE::DataAbstraction::OngoingCalculation ... >
173
160
 
174
- a_different_transport_calculation = CalculationSet.sets['my_emissions_calcualtions'][:transport].begin_calculation
161
+ a_different_transport_calculation = Calculations[:transport].begin_calculation
175
162
 
176
163
  #=> <AMEE::DataAbstraction::OngoingCalculation ... >
177
164
 
data/Rakefile CHANGED
@@ -13,16 +13,14 @@ rescue Bundler::BundlerError => e
13
13
  exit e.status_code
14
14
  end
15
15
  require 'rake'
16
- require 'spec'
17
- require 'spec/rake/spectask'
16
+ require 'rspec'
17
+ require 'rspec/core/rake_task'
18
18
 
19
19
  task :default => [:spec]
20
20
 
21
- Spec::Rake::SpecTask.new do |t|
22
- t.spec_opts = ['--options', "spec/spec.opts"]
23
- t.spec_files = FileList['spec/**/*_spec.rb']
24
- t.rcov = true
25
- t.rcov_opts = ['--exclude', 'spec,/*ruby*,/*gems*']
21
+ desc "Run specs"
22
+ RSpec::Core::RakeTask.new do |t|
23
+ # Put spec opts in a file named .rspec in root
26
24
  end
27
25
 
28
26
  require 'jeweler'
@@ -74,14 +72,17 @@ Jeweler::Tasks.new do |gem|
74
72
  end
75
73
  Jeweler::RubygemsDotOrgTasks.new
76
74
 
77
- task :default => :spec
78
-
79
- require 'rake/rdoctask'
80
- Rake::RDocTask.new do |rdoc|
81
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
75
+ require 'rcov/rcovtask'
76
+ desc "Generate code coverage"
77
+ RSpec::Core::RakeTask.new(:coverage) do |t|
78
+ t.rcov = true
79
+ t.rcov_opts = ['--exclude', 'spec']
80
+ end
82
81
 
83
- rdoc.rdoc_dir = 'rdoc'
84
- rdoc.title = "amee-data-abstraction #{version}"
85
- rdoc.rdoc_files.include('README*')
86
- rdoc.rdoc_files.include('lib/**/*.rb')
82
+ require 'rdoc/task'
83
+ RDoc::Task.new do |rd|
84
+ rd.title = "AMEE Data Abstraction"
85
+ rd.rdoc_dir = 'doc'
86
+ rd.main = "README"
87
+ rd.rdoc_files.include("README", "lib/**/*.rb")
87
88
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.1
1
+ 2.0.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amee-data-abstraction}
8
- s.version = "1.3.0"
8
+ s.version = "2.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Hetherington", "Andrew Berkeley", "James Smith", "George Palmer"]
12
- s.date = %q{2011-10-18}
12
+ s.date = %q{2011-09-28}
13
13
  s.description = %q{Part of the AMEEappkit this gem provides a data abstraction layer, decreasing the amount and detail of development required}
14
14
  s.email = %q{help@amee.com}
15
15
  s.extra_rdoc_files = [
@@ -28,7 +28,6 @@ Gem::Specification.new do |s|
28
28
  "amee-data-abstraction.gemspec",
29
29
  "examples/_calculator_form.erb",
30
30
  "examples/calculation_controller.rb",
31
- "init.rb",
32
31
  "lib/amee-data-abstraction.rb",
33
32
  "lib/amee-data-abstraction/calculation.rb",
34
33
  "lib/amee-data-abstraction/calculation_set.rb",
@@ -48,7 +47,6 @@ Gem::Specification.new do |s|
48
47
  "lib/core-extensions/hash.rb",
49
48
  "lib/core-extensions/ordered_hash.rb",
50
49
  "lib/core-extensions/proc.rb",
51
- "rails/init.rb",
52
50
  "spec/amee-data-abstraction/calculation_set_spec.rb",
53
51
  "spec/amee-data-abstraction/calculation_spec.rb",
54
52
  "spec/amee-data-abstraction/drill_spec.rb",
@@ -64,53 +62,52 @@ Gem::Specification.new do |s|
64
62
  "spec/core-extensions/hash_spec.rb",
65
63
  "spec/core-extensions/ordered_hash_spec.rb",
66
64
  "spec/core-extensions/proc_spec.rb",
67
- "spec/fixtures/config/calculations/electricity.rb",
68
- "spec/fixtures/config/calculations/electricity_and_transport.rb",
69
- "spec/fixtures/config/calculations/transport.rb",
70
- "spec/fixtures/config/electricity.rb",
65
+ "spec/fixtures/electricity.rb",
66
+ "spec/fixtures/electricity_and_transport.rb",
67
+ "spec/fixtures/transport.rb",
71
68
  "spec/spec.opts",
72
69
  "spec/spec_helper.rb"
73
70
  ]
74
71
  s.homepage = %q{http://github.com/AMEE/amee-data-abstraction}
75
72
  s.licenses = ["BSD 3-Clause"]
76
73
  s.require_paths = ["lib"]
77
- s.rubygems_version = %q{1.5.3}
74
+ s.rubygems_version = %q{1.4.2}
78
75
  s.summary = %q{Calculation and form building tool hiding details of AMEEconnect}
79
76
 
80
77
  if s.respond_to? :specification_version then
81
78
  s.specification_version = 3
82
79
 
83
80
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
84
- s.add_runtime_dependency(%q<amee>, ["~> 3.1"])
81
+ s.add_runtime_dependency(%q<amee>, ["~> 4.0"])
85
82
  s.add_runtime_dependency(%q<uuidtools>, ["= 2.1.2"])
86
- s.add_runtime_dependency(%q<quantify>, ["= 1.2.2"])
83
+ s.add_runtime_dependency(%q<quantify>, ["~> 2.0.0"])
87
84
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
88
85
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
89
- s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
90
- s.add_development_dependency(%q<rcov>, [">= 0"])
91
- s.add_development_dependency(%q<rspec_spinner>, ["= 1.1.3"])
86
+ s.add_development_dependency(%q<rspec>, ["= 2.6.0"])
92
87
  s.add_development_dependency(%q<flexmock>, ["> 0.8.6"])
88
+ s.add_development_dependency(%q<rcov>, [">= 0"])
89
+ s.add_development_dependency(%q<rdoc>, [">= 0"])
93
90
  else
94
- s.add_dependency(%q<amee>, ["~> 3.1"])
91
+ s.add_dependency(%q<amee>, ["~> 4.0"])
95
92
  s.add_dependency(%q<uuidtools>, ["= 2.1.2"])
96
- s.add_dependency(%q<quantify>, ["= 1.2.2"])
93
+ s.add_dependency(%q<quantify>, ["~> 2.0.0"])
97
94
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
98
95
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
99
- s.add_dependency(%q<rspec>, ["= 1.3.0"])
100
- s.add_dependency(%q<rcov>, [">= 0"])
101
- s.add_dependency(%q<rspec_spinner>, ["= 1.1.3"])
96
+ s.add_dependency(%q<rspec>, ["= 2.6.0"])
102
97
  s.add_dependency(%q<flexmock>, ["> 0.8.6"])
98
+ s.add_dependency(%q<rcov>, [">= 0"])
99
+ s.add_dependency(%q<rdoc>, [">= 0"])
103
100
  end
104
101
  else
105
- s.add_dependency(%q<amee>, ["~> 3.1"])
102
+ s.add_dependency(%q<amee>, ["~> 4.0"])
106
103
  s.add_dependency(%q<uuidtools>, ["= 2.1.2"])
107
- s.add_dependency(%q<quantify>, ["= 1.2.2"])
104
+ s.add_dependency(%q<quantify>, ["~> 2.0.0"])
108
105
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
109
106
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
110
- s.add_dependency(%q<rspec>, ["= 1.3.0"])
111
- s.add_dependency(%q<rcov>, [">= 0"])
112
- s.add_dependency(%q<rspec_spinner>, ["= 1.1.3"])
107
+ s.add_dependency(%q<rspec>, ["= 2.6.0"])
113
108
  s.add_dependency(%q<flexmock>, ["> 0.8.6"])
109
+ s.add_dependency(%q<rcov>, [">= 0"])
110
+ s.add_dependency(%q<rdoc>, [">= 0"])
114
111
  end
115
112
  end
116
113
 
@@ -27,4 +27,10 @@ require File.dirname(__FILE__) + '/amee-data-abstraction/metadatum'
27
27
  module AMEE::DataAbstraction
28
28
  # Connection to AMEE server.
29
29
  mattr_accessor :connection
30
+
31
+ if defined?(Rails)
32
+ def self.connection
33
+ AMEE::Rails.connection
34
+ end
35
+ end
30
36
  end
@@ -132,7 +132,7 @@ module AMEE
132
132
  end
133
133
 
134
134
  def explorer_url
135
- Rails.logger.info "#explorer_url method deprecated. Use #discover_url" if defined?(Rails) && Rails.logger.present?
135
+ ::Rails.logger.info "#explorer_url method deprecated. Use #discover_url" if defined? Rails
136
136
  discover_url
137
137
  end
138
138
 
@@ -36,95 +36,22 @@ module AMEE
36
36
  #
37
37
  class CalculationSet
38
38
 
39
- # Class variable holding all instantiated calculation sets keyed on the set
40
- # name.
39
+ # Initialize a <i>CalculationSet</i> with a "DSL" block, i.e. a block to be
40
+ # evaluated in the context of the instantiated CalculationSet
41
41
  #
42
- @@sets = {}
43
-
44
- # Convenience method for accessing the @@sets class variable
45
- def self.sets
46
- @@sets
47
- end
48
-
49
- # Retrieve a calculation set on the basis of a configuration file name or
50
- # relatiev/absolute file path. If configuration files are location within
51
- # the default Rails location under '/config/calculations' then the path and
52
- # the .rb extenstion can be omitted from the name.
53
- #
54
- def self.find(name)
55
- @@sets[name.to_sym] or load_set(name)
56
- end
57
-
58
- # Regenerate a configuration lock file assocaited with the master
59
- # configuration file <tt>name</tt>. Optionally set a custom path for the
60
- # lock file as <tt>output_path</tt>, otherwise the lock file path and
61
- # filename will be based upon the master file with the extension .lock.rb.
62
- #
63
- def self.regenerate_lock_file(name,output_path=nil)
64
- set = CalculationSet.find(name)
65
- set.generate_lock_file(output_path)
66
- end
67
-
68
- # Find a specific prototype calculation instance without specifying the set
69
- # to which it belongs.
70
- #
71
- def self.find_prototype_calculation(label)
72
- @@sets.each_pair do |name,set|
73
- set = find(name)
74
- return set[label] if set[label]
75
- end
76
- return nil
77
- end
78
-
79
- protected
80
-
81
- # Load a calculation set based on a filename or full path.
82
- def self.load_set(name)
83
- CalculationSet.new(name,:file => name) do
84
- instance_eval(File.open(self.config_path).read)
85
- end
86
- end
87
-
88
- DEFFAULT_RAILS_CONFIG_DIR = "config/calculations"
89
-
90
- # Find the config file assocaited with <tt>name</tt>. The method first checks
91
- # the default Rails configuration location (config/calculations) then the
92
- # file path described by <tt>name</tt> relative to the Rails root and by
93
- # absolute path.
94
- def self.find_config_file(name)
95
- default_config_dir = defined?(::Rails) ? "#{::Rails.root}/#{DEFFAULT_RAILS_CONFIG_DIR}" : nil
96
- if defined?(::Rails) && File.exists?("#{default_config_dir}/#{name.to_s}.rb")
97
- "#{default_config_dir}/#{name.to_s}.rb"
98
- elsif defined?(::Rails) && File.exists?("#{default_config_dir}/#{name.to_s}")
99
- "#{default_config_dir}/#{name.to_s}"
100
- elsif defined?(::Rails) && File.exists?("#{::Rails.root}/#{name}")
101
- "#{::Rails.root}/#{name}"
102
- elsif File.exists?(name)
103
- name
104
- else
105
- raise ArgumentError, "The config file '#{name}' could not be located"
106
- end
107
- end
108
-
109
- public
110
-
111
- attr_accessor :calculations, :name, :file
112
-
113
- # Initialise a new Calculation set. Specify the name of the calculation set
114
- # as the first argument. This name is used as the set key within the class
115
- # variable @@sets hash.
116
- #
117
- def initialize(name,options={},&block)
118
- raise ArgumentError, "Calculation set must have a name" unless name
119
- @name = name
120
- @file = CalculationSet.find_config_file(options[:file]) if options[:file]
121
- @calculations = ActiveSupport::OrderedHash.new
42
+ def initialize(options={},&block)
43
+ @calculations=ActiveSupport::OrderedHash.new
122
44
  @all_blocks=[]
123
45
  @all_options={}
124
46
  instance_eval(&block) if block
125
- @@sets[@name.to_sym] = self
126
47
  end
127
48
 
49
+ # Access the @calculations instance variable ordered hash. Keys are labels
50
+ # assocaited with each prototype calculation; values are the instantiated
51
+ # <i>PrototypeCalculation</i> objects
52
+ #
53
+ attr_accessor :calculations
54
+
128
55
  # Shorthand method for returning the prototype calculation which is represented
129
56
  # by a label matching <tt>sym</tt>
130
57
  #
@@ -167,77 +94,8 @@ module AMEE
167
94
  instance_exec(usage,&dsl_block)
168
95
  }
169
96
  end
170
- end
171
97
 
172
- # Returns the path to the configuration file for <tt>self</tt>. If a .lock
173
- # file exists, this takes precedence, otherwise the master config file
174
- # described by the <tt>#file</tt> attribute is returned.
175
- #
176
- def config_path
177
- lock_file_exists? ? lock_file_path : @file
178
98
  end
179
-
180
- # Returns the path to the configuration lock file
181
- def lock_file_path
182
- @file.gsub(".rb",".lock.rb") rescue nil
183
- end
184
-
185
- # Returns <tt>true</tt> if a configuration lock file exists. Otherwise,
186
- # returns <tt>false</tt>.
187
- #
188
- def lock_file_exists?
189
- File.exists?(lock_file_path)
190
- end
191
-
192
- # Generates a lock file for the calcuation set configuration. If no argument
193
- # is provided the, the lock file is generated using the filename and path
194
- # described by the <tt>#lock_file_path</tt> method. If a custom output
195
- # location is required, this can be provided optionally as an argument.
196
- #
197
- def generate_lock_file(output_path=nil)
198
- file = output_path || lock_file_path or raise ArgumentError,
199
- "No path for lock file known. Either set path for the master config file using the #file accessor method or provide as an argument"
200
- string = ""
201
- @calculations.values.each do |prototype_calculation|
202
- string += "calculation {\n\n"
203
- string += " name \"#{prototype_calculation.name}\"\n"
204
- string += " label :#{prototype_calculation.label}\n"
205
- string += " path \"#{prototype_calculation.path}\"\n\n"
206
- prototype_calculation.terms.each do |term|
207
- string += " #{term.class.to_s.split("::").last.downcase} {\n"
208
- string += " name \"#{term.name}\"\n" unless term.name.blank?
209
- string += " label :#{term.label}\n" unless term.label.blank?
210
- string += " path \"#{term.path}\"\n" unless term.path.blank?
211
- string += " value \"#{term.value}\"\n" unless term.value.blank?
212
-
213
- if term.is_a?(AMEE::DataAbstraction::Input)
214
- string += " fixed \"#{term.value}\"\n" if term.fixed? && !term.value.blank?
215
- if term.is_a?(AMEE::DataAbstraction::Drill)
216
- string += " choices \"#{term.choices.join('","')}\"\n" if term.instance_variable_defined?("@choices") && !term.choices.blank?
217
- elsif term.is_a?(AMEE::DataAbstraction::Profile)
218
- string += " choices [\"#{term.choices.join('","')}\"]\n" if term.instance_variable_defined?("@choices") && !term.choices.blank?
219
- end
220
- string += " optional!\n" if term.optional?
221
- end
222
-
223
- string += " default_unit :#{term.default_unit.label}\n" unless term.default_unit.blank?
224
- string += " default_per_unit :#{term.default_per_unit.label}\n" unless term.default_per_unit.blank?
225
- string += " alternative_units :#{term.alternative_units.map(&:label).join(', :')}\n" unless term.alternative_units.blank?
226
- string += " alternative_per_units :#{term.alternative_per_units.map(&:label).join(', :')}\n" unless term.alternative_per_units.blank?
227
- string += " unit :#{term.unit.label}\n" unless term.unit.blank?
228
- string += " per_unit :#{term.per_unit.label}\n" unless term.per_unit.blank?
229
- string += " type :#{term.type}\n" unless term.type.blank?
230
- string += " interface :#{term.interface}\n" unless term.interface.blank?
231
- string += " note \"#{term.note}\"\n" unless term.note.blank?
232
- string += " disable!\n" if !term.is_a?(AMEE::DataAbstraction::Drill) && term.disabled?
233
- string += " hide!\n" if term.hidden?
234
- string += " }\n\n"
235
- end
236
- string += "}\n\n"
237
- end
238
- File.open(file,'w') { |f| f.write string }
239
- end
240
-
241
99
  end
242
100
  end
243
101
  end