Class: Fet::Degree

Inherits:
Object
  • Object
show all
Defined in:
lib/fet/degree.rb

Overview

This class handles validation of degree names and extraction of values from it

Constant Summary collapse

DEGREE_NAMES =
[
  ["1"],
  ["#1", "b2"],
  ["2"],
  ["#2", "b3"],
  ["3"],
  ["4"],
  ["#4", "b5"],
  ["5"],
  ["#5", "b6"],
  ["6"],
  ["#6", "b7"],
  ["7"],
].deep_freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(degree_name) ⇒ Degree

Returns a new instance of Degree.



23
24
25
26
# File 'lib/fet/degree.rb', line 23

def initialize(degree_name)
  self.degree_name = degree_name
  validate_degree_name!
end

Instance Attribute Details

#degree_nameObject

Returns the value of attribute degree_name.



21
22
23
# File 'lib/fet/degree.rb', line 21

def degree_name
  @degree_name
end

Instance Method Details

#degree_accidentalObject



28
29
30
# File 'lib/fet/degree.rb', line 28

def degree_accidental
  return degree_name.size == 2 ? degree_name[0] : nil
end

#degree_indexObject



36
37
38
# File 'lib/fet/degree.rb', line 36

def degree_index
  return DEGREE_NAMES.index { |degree_names| degree_names.include?(degree_name) }
end

#degree_valueObject



32
33
34
# File 'lib/fet/degree.rb', line 32

def degree_value
  return degree_name.size == 2 ? degree_name[1].to_i : degree_name[0].to_i
end