Class: SecID::CFI::Classification
- Inherits:
-
Object
- Object
- SecID::CFI::Classification
- Defined in:
- lib/sec_id/cfi/classification.rb
Overview
Instance Attribute Summary collapse
-
#attributes ⇒ AttributeSet
readonly
The decoded attribute fields.
-
#category ⇒ Field
readonly
The category field.
-
#group ⇒ Field
readonly
The group field.
Instance Method Summary collapse
- #as_json ⇒ Hash{Symbol => Object}
-
#initialize(category_code, group_code, letters) ⇒ Classification
constructor
A new instance of Classification.
- #to_h ⇒ Hash{Symbol => Object}
-
#to_s ⇒ String
Renders a human-readable classification string from the ISO labels.
Constructor Details
#initialize(category_code, group_code, letters) ⇒ Classification
Returns a new instance of Classification.
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
#attributes ⇒ AttributeSet (readonly)
Returns the decoded attribute fields.
25 26 27 |
# File 'lib/sec_id/cfi/classification.rb', line 25 def attributes @attributes end |
#category ⇒ Field (readonly)
Returns the category field.
19 20 21 |
# File 'lib/sec_id/cfi/classification.rb', line 19 def category @category end |
#group ⇒ Field (readonly)
Returns the group field.
22 23 24 |
# File 'lib/sec_id/cfi/classification.rb', line 22 def group @group end |
Instance Method Details
#as_json ⇒ Hash{Symbol => Object}
52 53 54 |
# File 'lib/sec_id/cfi/classification.rb', line 52 def as_json(*) to_h end |
#to_h ⇒ 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_s ⇒ String
Renders a human-readable classification string from the ISO labels.
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 |