Class: Jinx::AttributeEnumerator
- Includes:
- Enumerable
- 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_property {|attribute| ... } ⇒ Property
The first attribute metadata whose attribute satisfies the block.
-
#detect_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
#collection?, #compact, #compact_map, #detect_value, #detect_with_value, #difference, #empty?, #enumerate, #filter, #first, #flatten, #hashify, #intersect, #join, #last, #partial_sort, #partial_sort_by, #pp_s, #pretty_print, #pretty_print_cycle, #qp, #size, #to_compact_hash, #to_compact_hash_with_index, #to_enum, #to_series, #transform, #transitive_closure, #union
Constructor Details
#initialize(hash) {|prop| ... } ⇒ AttributeEnumerator
Returns a new instance of AttributeEnumerator.
12 13 14 15 16 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 12 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.
69 70 71 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 69 def compose AttributeEnumerator.new(@hash) { |prop| @filter.call(prop) and yield(prop) } end |
#detect_property {|attribute| ... } ⇒ Property
Returns the first attribute metadata whose attribute satisfies the block.
52 53 54 55 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 52 def detect_property each_pair { |pa, prop| return prop if yield(pa) } nil end |
#detect_with_property {|prop| ... } ⇒ Symbol
Returns the first attribute whose metadata satisfies the block.
60 61 62 63 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 60 def detect_with_property each_pair { |pa, prop| return pa if yield(prop) } nil end |
#each_attribute {|attribute| ... } ⇒ Object Also known as: each
32 33 34 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 32 def each_attribute(&block) each_pair { |pa, prop| yield(pa) } end |
#each_pair {|attribute, prop| ... } ⇒ Object
21 22 23 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 21 def each_pair @hash.each { |pa, prop| yield(pa, prop) if @filter.call(prop) } end |
#each_property {|prop| ... } ⇒ Object
40 41 42 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 40 def each_property each_pair { |pa, prop| yield(prop) } end |
#enum_pairs ⇒ <(Symbol, Property)>
Returns the (symbol, attribute) enumerator.
26 27 28 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 26 def enum_pairs enum_for(:each_pair) end |
#properties ⇒ <Property>
Returns the property enumerator.
45 46 47 |
# File 'lib/jinx/metadata/attribute_enumerator.rb', line 45 def properties @prop_enum ||= enum_for(:each_property) end |