Module: Calculus::ManureManagementPlan

Defined in:
lib/calculus/manure_management_plan.rb,
lib/calculus/manure_management_plan/method.rb,
lib/calculus/manure_management_plan/external.rb

Defined Under Namespace

Classes: External, Method

Class Method Summary collapse

Class Method Details

.compute(options = {}) ⇒ Object


10
11
12
# File 'lib/calculus/manure_management_plan.rb', line 10

def compute(options = {})
  new_method(options).compute
end

.estimate_expected_yield(options = {}) ⇒ Object


6
7
8
# File 'lib/calculus/manure_management_plan.rb', line 6

def estimate_expected_yield(options = {})
  new_method(options).estimate_expected_yield
end

.find_method(name) ⇒ Object


14
15
16
17
18
# File 'lib/calculus/manure_management_plan.rb', line 14

def find_method(name)
  class_name = @registered_methods[name]
  raise "Cannot find method: #{name.inspect}" unless class_name
  class_name.constantize
end

.human_method_name(name, options = {}) ⇒ Object


40
41
42
# File 'lib/calculus/manure_management_plan.rb', line 40

def human_method_name(name, options = {})
  "manure_management_method.#{name}".t({ default: ["labels.#{name}".to_sym, name.to_s.humanize] }.merge(options))
end

.method_exist?(name) ⇒ Boolean

Returns:

  • (Boolean)

20
21
22
# File 'lib/calculus/manure_management_plan.rb', line 20

def method_exist?(name)
  @registered_methods[name].present?
end

.method_selection(options = {}) ⇒ Object

Produces an array for select options


34
35
36
37
38
# File 'lib/calculus/manure_management_plan.rb', line 34

def method_selection(options = {})
  @registered_methods.keys.collect do |n|
    [human_method_name(n, options), n.to_s]
  end.sort_by(&:first)
end

.new_method(options) ⇒ Object


24
25
26
# File 'lib/calculus/manure_management_plan.rb', line 24

def new_method(options)
  find_method(options[:method]).new(options)
end

.register_method(name, class_name) ⇒ Object

Register a method for manure management plan


29
30
31
# File 'lib/calculus/manure_management_plan.rb', line 29

def register_method(name, class_name)
  @registered_methods[name] = class_name
end