Class: SecID::CFI::Field

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

Overview

A single decoded CFI position: the category, the group, or one attribute. Carries its raw CFI letter (#code), semantic symbol (#name), ISO label (#label), and — for attributes — the group meaning it answers (#meaning). Defines a <name>? predicate for every symbol in its domain, so category.equity? is answerable while an out-of-domain predicate such as category.voting? raises NoMethodError.

Built by Classification; also usable on its own.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(code, name, label, domain, meaning: nil) ⇒ Field

Returns a new instance of Field.

Parameters:

  • code (String)
  • name (Symbol)
  • label (String)
  • domain (Array<Symbol>)

    the symbols this field may hold; one <symbol>? predicate per entry

  • meaning (Symbol, nil) (defaults to: nil)


31
32
33
34
35
36
37
38
# File 'lib/sec_id/cfi/field.rb', line 31

def initialize(code, name, label, domain, meaning: nil)
  @code = code
  @name = name
  @label = label
  @meaning = meaning
  domain.each { |symbol| define_singleton_method(:"#{symbol}?") { @name == symbol } }
  freeze
end

Instance Attribute Details

#codeString (readonly)

Returns the raw CFI letter (e.g. "E", "V").

Returns:

  • (String)

    the raw CFI letter (e.g. "E", "V")



15
16
17
# File 'lib/sec_id/cfi/field.rb', line 15

def code
  @code
end

#labelString (readonly)

Returns the authoritative ISO label.

Returns:

  • (String)

    the authoritative ISO label



21
22
23
# File 'lib/sec_id/cfi/field.rb', line 21

def label
  @label
end

#meaningSymbol? (readonly)

Returns the group meaning for attribute fields, nil for category/group.

Returns:

  • (Symbol, nil)

    the group meaning for attribute fields, nil for category/group



24
25
26
# File 'lib/sec_id/cfi/field.rb', line 24

def meaning
  @meaning
end

#nameSymbol (readonly)

Returns the semantic symbol (e.g. :equity, :voting).

Returns:

  • (Symbol)

    the semantic symbol (e.g. :equity, :voting)



18
19
20
# File 'lib/sec_id/cfi/field.rb', line 18

def name
  @name
end

Instance Method Details

#as_jsonHash{Symbol => Object}

Returns:

  • (Hash{Symbol => Object})


51
52
53
# File 'lib/sec_id/cfi/field.rb', line 51

def as_json(*)
  to_h
end

#to_hHash{Symbol => Object}

Returns:

  • (Hash{Symbol => Object})


46
47
48
# File 'lib/sec_id/cfi/field.rb', line 46

def to_h
  { code: code, name: name, label: label }
end

#to_sString

Returns the ISO label.

Returns:

  • (String)

    the ISO label



41
42
43
# File 'lib/sec_id/cfi/field.rb', line 41

def to_s
  label
end