Module: Gather
- Includes:
- Enumerable
- Included in:
- Changes
- Defined in:
- lib/gather.rb
Overview
Provides instance method gather and class method property Allows properties to be Enumerable.
Defined Under Namespace
Modules: ClassMethods
Classes: UniqueArray
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.included(base) ⇒ Object
99
100
101
|
# File 'lib/gather.rb', line 99
def self.included( base )
base.extend( ClassMethods )
end
|
Instance Method Details
#[](symbol) ⇒ Object
86
87
88
|
# File 'lib/gather.rb', line 86
def []( symbol )
send( symbol )
end
|
#[]=(symbol, value) ⇒ Object
90
91
92
|
# File 'lib/gather.rb', line 90
def []=( symbol, value )
send( symbol, value )
end
|
#each(&block) ⇒ Object
94
95
96
|
# File 'lib/gather.rb', line 94
def each( &block )
self.class.properties.each( &block )
end
|
#gather(args = {}, &block) ⇒ Object
Evaluate the block and gather options from args. Even if it’s nil. Return self
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/gather.rb', line 42
def gather( args = {}, &block )
unless args.nil?
args.each do |key,value|
self.send( key, value )
end
end
unless block.nil?
if block.arity == -1
instance_eval &block
else
yield self
end
end
self
end
|
#merge(hash) ⇒ Object
return a new hash merged with the argument
82
83
84
|
# File 'lib/gather.rb', line 82
def merge( hash )
to_hash.merge( hash )
end
|
#merge!(hash) ⇒ Object
set all values specified in the hash
74
75
76
|
# File 'lib/gather.rb', line 74
def merge!( hash )
hash.each {|k,v| send( k, v ) }
end
|
#properties ⇒ Object
59
60
61
|
# File 'lib/gather.rb', line 59
def properties
self.class.properties
end
|
#start=(value) ⇒ Object
77
78
79
|
# File 'lib/gather.rb', line 77
def start=( value )
Time.new( value.to_n * 60 * 60 )
end
|
#to_a(properties = self.class.properties) ⇒ Object
Also known as:
values
68
69
70
|
# File 'lib/gather.rb', line 68
def to_a( properties = self.class.properties )
properties.inject([]) {|s,x| s << send(x) }
end
|
#to_hash(properties = self.class.properties) ⇒ Object
return a hash of the properties
64
65
66
|
# File 'lib/gather.rb', line 64
def to_hash( properties = self.class.properties )
properties.inject({}) {|s,x| s[x] = send(x); s}
end
|