Class: Fortune::P_abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/fortune/p_abstract.rb

Overview

Permutations

Direct Known Subclasses

A, C, C_repetition, Pn, Pn_repetition

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(h, format = {:n => :elements, :k => :select}) ⇒ P_abstract

Returns a new instance of P_abstract.

Raises:

  • (ArgumentError)


7
8
9
10
11
12
# File 'lib/fortune/p_abstract.rb', line 7

def initialize(h, format = {:n => :elements, :k => :select})
  raise ArgumentError.new("Error: arguments should be hash") unless h.is_a?(Hash)
  self.n = h[:n] || h[format[:n]]
  self.k = h[:k] || h[format[:k]]
  self.value = h
end

Instance Attribute Details

#kObject

Returns the value of attribute k.



5
6
7
# File 'lib/fortune/p_abstract.rb', line 5

def k
  @k
end

#nObject

Returns the value of attribute n.



5
6
7
# File 'lib/fortune/p_abstract.rb', line 5

def n
  @n
end

#valueObject

Returns the value of attribute value.



5
6
7
# File 'lib/fortune/p_abstract.rb', line 5

def value
  @value
end

Class Method Details

.calc(n) ⇒ Object



14
15
16
# File 'lib/fortune/p_abstract.rb', line 14

def self.calc(n)
  self.new(n).value
end