Class: CosSinCalc::Triangle::VariableHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/cossincalc/triangle/variable_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize ⇒ VariableHash

Initializes the variables.



7
8
9
10
# File 'lib/cossincalc/triangle/variable_hash.rb', line 7

def initialize
  super()
  CosSinCalc::Triangle::VARIABLES.each { |v| self[v] = nil }
end

Instance Attribute Details

#unit ⇒ Object

Returns the value of attribute unit.



4
5
6
# File 'lib/cossincalc/triangle/variable_hash.rb', line 4

def unit
  @unit
end

Instance Method Details

#[](vars) ⇒ Object

If a symbol is given, returns the associated value. If an array of symbols is given, returns an array of the associated values.



14
15
16
# File 'lib/cossincalc/triangle/variable_hash.rb', line 14

def [](vars)
  vars.is_a?(Array) ? vars.map { |v| super(v) } : super(vars)
end

#amount ⇒ Object

Returns the amount of variables that have a value.



19
20
21
# File 'lib/cossincalc/triangle/variable_hash.rb', line 19

def amount
  self.values.compact.size
end

#known(vars = CosSinCalc::Triangle::VARIABLES) ⇒ Object

Returns an array of variables whose values are known.



24
25
26
# File 'lib/cossincalc/triangle/variable_hash.rb', line 24

def known(vars = CosSinCalc::Triangle::VARIABLES)
  vars.reject { |v| !self[v] }
end

#unknown(vars = CosSinCalc::Triangle::VARIABLES) ⇒ Object

Returns an array of variables whose values are unknown.



29
30
31
# File 'lib/cossincalc/triangle/variable_hash.rb', line 29

def unknown(vars = CosSinCalc::Triangle::VARIABLES)
  vars.reject { |v| self[v] }
end