Class: Mapper
- Inherits:
-
Array
- Object
- Array
- Mapper
- Defined in:
- lib/mapper.rb,
lib/mapper/all.rb,
lib/mapper/some.rb
Overview
Represents mapped objects holder.
Defined Under Namespace
Class Method Summary collapse
-
.[](*args) ⇒ Object
Alias for #new.
Instance Method Summary collapse
-
#all ⇒ Object
Produces reductor which passes call with given arguments to each object.
-
#initialize(*objs) ⇒ Mapper
constructor
Constructor.
-
#some(&block) ⇒ Object
Produces reductor which passes call with given arguments to each object from oldest to newest in aggregator if the output of given block isn’t
true
.
Constructor Details
#initialize(*objs) ⇒ Mapper
Constructor.
If only one argument, and it’s Array, content will be treaten as matter for mapping.
43 44 45 46 47 48 49 |
# File 'lib/mapper.rb', line 43 def initialize(*objs) if (objs.length == 1) and (objs.first.kind_of? Array) self.merge! objs.first else self.merge! objs end end |
Class Method Details
.[](*args) ⇒ Object
Alias for #new.
32 33 34 |
# File 'lib/mapper.rb', line 32 def self.[](*args) self::new(*args) end |
Instance Method Details
#all ⇒ Object
Produces reductor which passes call with given arguments to each object.
56 57 58 59 60 61 62 |
# File 'lib/mapper.rb', line 56 def all if @all.nil? @all = All::new(self) end return @all end |
#some(&block) ⇒ Object
Produces reductor which passes call with given arguments to each object from oldest to newest in aggregator if the output of given block isn’t true
.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/mapper.rb', line 70 def some(&block) # Returns from cache if not @some.nil? and block.nil? return @some end # In otherwise, creates new default = false if block.nil? block = Proc::new { |v| v.to_b } default = true end some = Some::new(self, &block) if (default == true) and @some.nil? @some = some end return some end |