Class: SecId::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sec_id/base.rb

Direct Known Subclasses

CUSIP, FIGI, ISIN, SEDOL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_sec_id_number) ⇒ Base

Returns a new instance of Base.

Raises:

  • (NotImplementedError)


47
48
49
# File 'lib/sec_id/base.rb', line 47

def initialize(_sec_id_number)
  raise NotImplementedError
end

Instance Attribute Details

#check_digitObject (readonly)

Returns the value of attribute check_digit.



27
28
29
# File 'lib/sec_id/base.rb', line 27

def check_digit
  @check_digit
end

#full_numberObject (readonly)

Returns the value of attribute full_number.



27
28
29
# File 'lib/sec_id/base.rb', line 27

def full_number
  @full_number
end

#identifierObject (readonly)

Returns the value of attribute identifier.



27
28
29
# File 'lib/sec_id/base.rb', line 27

def identifier
  @identifier
end

Class Method Details

.check_digit(id) ⇒ Object



42
43
44
# File 'lib/sec_id/base.rb', line 42

def check_digit(id)
  new(id).calculate_check_digit
end

.restore!(id_without_check_digit) ⇒ Object



38
39
40
# File 'lib/sec_id/base.rb', line 38

def restore!(id_without_check_digit)
  new(id_without_check_digit).restore!
end

.valid?(id) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/sec_id/base.rb', line 30

def valid?(id)
  new(id).valid?
end

.valid_format?(id) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/sec_id/base.rb', line 34

def valid_format?(id)
  new(id).valid_format?
end

Instance Method Details

#calculate_check_digitObject

Raises:

  • (NotImplementedError)


66
67
68
# File 'lib/sec_id/base.rb', line 66

def calculate_check_digit
  raise NotImplementedError
end

#restore!Object



61
62
63
64
# File 'lib/sec_id/base.rb', line 61

def restore!
  @check_digit = calculate_check_digit
  @full_number = to_s
end

#to_sObject Also known as: to_str



70
71
72
# File 'lib/sec_id/base.rb', line 70

def to_s
  "#{identifier}#{check_digit}"
end

#valid?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/sec_id/base.rb', line 51

def valid?
  return false unless valid_format?

  check_digit == calculate_check_digit
end

#valid_format?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/sec_id/base.rb', line 57

def valid_format?
  identifier ? true : false
end