Class: SecID::CFI::AttributeSet
- Inherits:
-
Object
- Object
- SecID::CFI::AttributeSet
- Includes:
- Enumerable
- Defined in:
- lib/sec_id/cfi/attribute_set.rb
Overview
The ordered collection of decoded attribute Fields. Enumerable over the fields; also answers each present meaning as a reader method (e.g. `#voting_right`) and via `#[]` (nil-safe). Built by Classification.
Instance Method Summary collapse
- #[](meaning) ⇒ Field?
- #as_json ⇒ Hash{Symbol => Hash}
- #each {|field| ... } ⇒ Enumerator, self
- #empty? ⇒ Boolean
-
#initialize(fields) ⇒ AttributeSet
constructor
A new instance of AttributeSet.
- #to_h ⇒ Hash{Symbol => Hash}
Constructor Details
#initialize(fields) ⇒ AttributeSet
Returns a new instance of AttributeSet.
12 13 14 15 16 |
# File 'lib/sec_id/cfi/attribute_set.rb', line 12 def initialize(fields) @fields = fields fields.each { |field| define_singleton_method(field.meaning) { field } } freeze end |
Instance Method Details
#[](meaning) ⇒ Field?
29 30 31 |
# File 'lib/sec_id/cfi/attribute_set.rb', line 29 def [](meaning) find { |field| field.meaning == meaning } end |
#as_json ⇒ Hash{Symbol => Hash}
44 45 46 |
# File 'lib/sec_id/cfi/attribute_set.rb', line 44 def as_json(*) to_h end |
#each {|field| ... } ⇒ Enumerator, self
20 21 22 23 24 25 |
# File 'lib/sec_id/cfi/attribute_set.rb', line 20 def each(&block) return to_enum(:each) unless block @fields.each(&block) self end |
#empty? ⇒ Boolean
34 35 36 |
# File 'lib/sec_id/cfi/attribute_set.rb', line 34 def empty? @fields.empty? end |
#to_h ⇒ Hash{Symbol => Hash}
39 40 41 |
# File 'lib/sec_id/cfi/attribute_set.rb', line 39 def to_h @fields.to_h { |field| [field.meaning, field.to_h] } end |