Class: Object
- Inherits:
-
BasicObject
- Includes:
- ChainAnalysis
- Defined in:
- lib/kuku.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#average_growth, #elements, #mean, #stability
Instance Attribute Details
Returns the value of attribute next.
19
20
21
|
# File 'lib/kuku.rb', line 19
def next
@next
end
|
Returns the value of attribute previous.
19
20
21
|
# File 'lib/kuku.rb', line 19
def previous
@previous
end
|
Instance Method Details
#as_number ⇒ Object
23
24
25
26
27
28
|
# File 'lib/kuku.rb', line 23
def as_number
return self if self.class != String
signing = start_with?("(") && end_with?(")") ? -1 : 1
s = gsub(",", "").gsub("--", "").gsub("(", "").gsub(")", "")
!s.empty? ? s.to_i * signing : 0
end
|
#as_unchained_array ⇒ Object
29
30
31
32
33
|
# File 'lib/kuku.rb', line 29
def as_unchained_array
return Array[self] if self.next == nil
a = Array[self] << self.next.as_unchained_array
a.flatten
end
|
#attributes ⇒ Object
37
38
39
40
41
|
# File 'lib/kuku.rb', line 37
def attributes
!instance_variables.empty? ?
(instance_variables_as_hash) :
(struct_as_hash self)
end
|
#hash_key_for(v) ⇒ Object
54
55
56
|
# File 'lib/kuku.rb', line 54
def hash_key_for v
v.to_s.gsub("@","").to_sym
end
|
#instance_variables_as_hash ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/kuku.rb', line 42
def instance_variables_as_hash
hash = Hash.new
instance_variables.each{|v|
hash[hash_key_for(v)] = instance_variable_get(v)
}
hash
end
|
20
21
22
|
# File 'lib/kuku.rb', line 20
def nvl v
v ? v : 0
end
|
#struct_as_hash(obj) ⇒ Object
49
50
51
52
53
|
# File 'lib/kuku.rb', line 49
def struct_as_hash obj
hash = Hash.new
obj.each_pair {|name, value| hash[name] = value}
hash
end
|
#update_attributes(hash) ⇒ Object
34
35
36
|
# File 'lib/kuku.rb', line 34
def update_attributes hash
hash.each { |name, value| instance_variable_set("@#{name}", value) }
end
|