Class: Jinx::AttributeEnumerator
- Includes:
- Enumerable, Collection
- Defined in:
- lib/jinx/metadata/attribute_enumerator.rb
Overview
A filter on the standard attribute symbol => metadata hash that yields each attribute which satisfies the attribute metadata condition.
Instance Method Summary collapse
-
#compose {|prop| ... } ⇒ AttributeEnumerator
A new eumerator which applies the filter block given to this method with the Property enumerated by this enumerator.
-
#detect_attribute_with_property {|prop| ... } ⇒ Symbol
The first attribute whose metadata satisfies the block.
- #each_attribute {|attribute| ... } ⇒ Object (also: #each)
- #each_pair {|attribute, prop| ... } ⇒ Object
- #each_property {|prop| ... } ⇒ Object
-
#enum_pairs ⇒ <(Symbol, Property)>
The (symbol, attribute) enumerator.
-
#initialize(hash) {|prop| ... } ⇒ AttributeEnumerator
constructor
A new instance of AttributeEnumerator.
-
#properties ⇒ <Property>
The property enumerator.
Methods included from Enumerable
#enumerate, #pp_s, #pretty_print, #pretty_print_cycle, #qp, #to_enum, #transitive_closure
Methods included from Collection
#compact, #compact_map, #detect_value, #detect_with_value, #difference, #empty?, #filter, #first, #flatten, #hashify, #intersect, #join, #last, #partial_sort, #partial_sort!, #partial_sort_by, #size, #to_compact_hash, #to_compact_hash_with_index, #to_series, #transform, #union
Constructor Details
#initialize(hash) {|prop| ... } ⇒ AttributeEnumerator
Returns a new instance of AttributeEnumerator.
14 15 16 17 18 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 14 def initialize(hash, &filter) raise ArgumentError.new("Attribute filter missing hash argument") if hash.nil? @hash = hash @filter = block_given? ? filter : Proc.new { true } end |
Instance Method Details
#compose {|prop| ... } ⇒ AttributeEnumerator
Returns a new eumerator which applies the filter block given to this method with the Property enumerated by this enumerator.
63 64 65 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 63 def compose AttributeEnumerator.new(@hash) { |prop| yield(prop) if @filter.call(prop) } end |
#detect_attribute_with_property {|prop| ... } ⇒ Symbol
Returns the first attribute whose metadata satisfies the block.
54 55 56 57 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 54 def detect_attribute_with_property each_pair { |pa, prop| return pa if yield(prop) } nil end |
#each_attribute {|attribute| ... } ⇒ Object Also known as: each
34 35 36 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 34 def each_attribute(&block) each_pair { |pa, prop| yield(pa) } end |
#each_pair {|attribute, prop| ... } ⇒ Object
23 24 25 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 23 def each_pair @hash.each { |pa, prop| yield(pa, prop) if @filter.call(prop) } end |
#each_property {|prop| ... } ⇒ Object
42 43 44 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 42 def each_property each_pair { |pa, prop| yield(prop) } end |
#enum_pairs ⇒ <(Symbol, Property)>
Returns the (symbol, attribute) enumerator.
28 29 30 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 28 def enum_pairs enum_for(:each_pair) end |
#properties ⇒ <Property>
Returns the property enumerator.
47 48 49 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 47 def properties @prop_enum ||= enum_for(:each_property) end |