Class: SecID::CFI::Classification

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

Overview

The decoded ISO 10962:2021 classification of a valid CFI, built by #decode. A frozen value object exposing the category, group, and each attribute as Field objects, plus #to_s and #to_h/#as_json.

Examples:

Decode an equity CFI

c = SecID::CFI.new('ESVUFR').decode
c.category.name                     #=> :equity
c.category.equity?                  #=> true
c.group.label                       #=> "Common/Ordinary shares"
c.attributes.voting_right.voting?   #=> true
c.attributes.payment_status.label   #=> "Fully paid"
c.to_s                              #=> "Equities / Common/Ordinary shares: Voting, ..."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(category_code, group_code, letters) ⇒ Classification

Returns a new instance of Classification.

Parameters:

  • category_code (String)
  • group_code (String)
  • letters (Array<String>)

    the four attribute letters (positions 3-6)



30
31
32
33
34
35
# File 'lib/sec_id/cfi/classification.rb', line 30

def initialize(category_code, group_code, letters)
  @category = build_category(category_code)
  @group = build_group(category_code, group_code)
  @attributes = build_attributes(category_code, group_code, letters)
  freeze
end

Instance Attribute Details

#attributesAttributeSet (readonly)

Returns the decoded attribute fields.

Returns:



25
26
27
# File 'lib/sec_id/cfi/classification.rb', line 25

def attributes
  @attributes
end

#categoryField (readonly)

Returns the category field.

Returns:

  • (Field)

    the category field



19
20
21
# File 'lib/sec_id/cfi/classification.rb', line 19

def category
  @category
end

#groupField (readonly)

Returns the group field.

Returns:

  • (Field)

    the group field



22
23
24
# File 'lib/sec_id/cfi/classification.rb', line 22

def group
  @group
end

Instance Method Details

#as_jsonHash{Symbol => Object}

Returns:

  • (Hash{Symbol => Object})


52
53
54
# File 'lib/sec_id/cfi/classification.rb', line 52

def as_json(*)
  to_h
end

#to_hHash{Symbol => Object}

Returns:

  • (Hash{Symbol => Object})


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

def to_h
  { category: category.to_h, group: group.to_h, attributes: attributes.to_h }
end

#to_sString

Renders a human-readable classification string from the ISO labels.

Returns:

  • (String)


40
41
42
43
44
# File 'lib/sec_id/cfi/classification.rb', line 40

def to_s
  values = attributes.map(&:label).join(', ')
  head = "#{category.label} / #{group.label}"
  values.empty? ? head : "#{head}: #{values}"
end