Class: Laser::Frequency

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/laser/support/frequency.rb

Constant Summary

NEVER =
self.new(:never, 0)
MAYBE =
self.new(:maybe, 1)
ALWAYS =
self.new(:always, 2)
LOOKUP =
{never: NEVER, maybe: MAYBE, always: ALWAYS}

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Comparable

#<, #<=, #==, #>, #>=, #between?, compare_int

Constructor Details

- (Frequency) initialize(name, val)

Returns a new instance of Frequency



5
6
7
8
# File 'lib/laser/support/frequency.rb', line 5

def initialize(name, val)
  @name = name
  @val = val
end

Instance Attribute Details

- (Object) name (readonly)

Returns the value of attribute name



4
5
6
# File 'lib/laser/support/frequency.rb', line 4

def name
  @name
end

- (Object) val (readonly)

Returns the value of attribute val



4
5
6
# File 'lib/laser/support/frequency.rb', line 4

def val
  @val
end

Class Method Details

+ (Object) [](sym)



28
29
30
# File 'lib/laser/support/frequency.rb', line 28

def self.[](sym)
  LOOKUP[sym]
end

+ (Object) combine_samples(samples)



32
33
34
35
36
37
38
39
# File 'lib/laser/support/frequency.rb', line 32

def self.combine_samples(samples)
  return NEVER if samples.empty?
  base = samples.first
  samples[1..-1].each do |sample|
    return MAYBE if sample > base || sample < base
  end
  base
end

+ (Object) for_samples(yes, no)



41
42
43
44
45
46
47
48
49
# File 'lib/laser/support/frequency.rb', line 41

def self.for_samples(yes, no)
  if no && !yes
    NEVER
  elsif no && yes
    MAYBE
  else  # !no && yes
    ALWAYS
  end
end

Instance Method Details

- (Object) <=>(other)



19
20
21
# File 'lib/laser/support/frequency.rb', line 19

def <=>(other)
  @val <=> other.val
end

- (Object) ===(other)



10
11
12
# File 'lib/laser/support/frequency.rb', line 10

def ===(other)
  equal? other
end

- (Object) to_s Also known as: inspect



14
15
16
# File 'lib/laser/support/frequency.rb', line 14

def to_s
  @name.to_s
end