Class: NudgeType::ProportionType
- Inherits:
-
Object
- Object
- NudgeType::ProportionType
show all
- Extended by:
- TypeBehaviors
- Defined in:
- lib/interpreter/types/proportion_type.rb
Class Method Summary
collapse
any_value, extended, from_s, random_value, recognizes?, to_nudgecode
Class Method Details
.any_value(options = {}) ⇒ Object
35
36
37
|
# File 'lib/interpreter/types/proportion_type.rb', line 35
def self.any_value(options ={})
self.random_value(options)
end
|
.default_highest ⇒ Object
12
13
14
|
# File 'lib/interpreter/types/proportion_type.rb', line 12
def self.default_highest
@default_highest
end
|
.default_lowest ⇒ Object
8
9
10
|
# File 'lib/interpreter/types/proportion_type.rb', line 8
def self.default_lowest
@default_lowest
end
|
.from_s(string_value) ⇒ Object
27
28
29
|
# File 'lib/interpreter/types/proportion_type.rb', line 27
def self.from_s(string_value)
(string_value.to_f != 1.0) ? (string_value.to_f % 1.0) : 1.0
end
|
.random_value(params = {}) ⇒ Object
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/interpreter/types/proportion_type.rb', line 16
def self.random_value(params = {})
bottom = params[:proportion_lower_bound] || @default_lowest
top = params[:proportion_upper_bound] || @default_highest
raise ArgumentError, "ProportionType#{random_value} bounds must be in range [0.0,1.0]" unless
(0.0..1.0).include?(bottom) && (0.0..1.0).include?(top)
raise ArgumentError, "ProportionType#{random_value} bounds are inverted" unless
bottom <= top
range = top - bottom
(rand*range) + bottom
end
|
.recognizes?(a_thing) ⇒ Boolean
31
32
33
|
# File 'lib/interpreter/types/proportion_type.rb', line 31
def self.recognizes?(a_thing)
!a_thing.kind_of?(String) && !a_thing.nil? && a_thing.respond_to?(:to_f)
end
|