Class: Danica::Common
- Inherits:
-
Object
show all
- Defined in:
- lib/danica/common.rb,
lib/danica/common/class_methods.rb,
lib/danica/common/variables_builder.rb
Defined Under Namespace
Classes: VariablesBuilder
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#variables ⇒ Object
Returns the value of attribute variables.
6
7
8
|
# File 'lib/danica/common.rb', line 6
def variables
@variables
end
|
Class Method Details
.variables(*names) ⇒ Object
3
4
5
|
# File 'lib/danica/common/class_methods.rb', line 3
def variables(*names)
VariablesBuilder.new(names, self).build
end
|
.variables_names ⇒ Object
7
8
9
|
# File 'lib/danica/common/class_methods.rb', line 7
def variables_names
@variables_names ||= []
end
|
Instance Method Details
#calculate(*args) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/danica/common.rb', line 12
def calculate(*args)
vars_map = args.
vars_map = variables_value_hash.merge(vars_map)
vars_map.each do |k, v|
unless v && (v.is_a?(Fixnum) || v.valued?)
vars_map[k] = args.shift
end
end
self.class.new(vars_map).to_f
end
|
#to_f ⇒ Object
8
9
10
|
# File 'lib/danica/common.rb', line 8
def to_f
raise 'Not IMplemented yet'
end
|
#valued? ⇒ Boolean
40
41
42
43
44
|
# File 'lib/danica/common.rb', line 40
def valued?
to_f.present?
rescue Exception::NotDefined
false
end
|
#variables_hash ⇒ Object
50
51
52
|
# File 'lib/danica/common.rb', line 50
def variables_hash
@variabels_map ||= (@variables || []).as_hash(self.class.variables_names)
end
|
#variables_value_hash ⇒ Object
54
55
56
|
# File 'lib/danica/common.rb', line 54
def variables_value_hash
variables.map(&:value).as_hash(self.class.variables_names)
end
|