Class: BucketMaker::Series
- Inherits:
-
Object
- Object
- BucketMaker::Series
- Defined in:
- lib/bucket_maker/series.rb
Overview
Class which holds all the Series based information
Constant Summary collapse
- SERIES_DESCRIPTION =
'description'- SERIES_USER_AFTER =
'created_after'- SERIES_BUCKETS =
'buckets'
Instance Attribute Summary collapse
-
#buckets ⇒ Object
readonly
Returns the value of attribute buckets.
-
#created_after ⇒ Object
readonly
Returns the value of attribute created_after.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#bucket_with_name(bucket_name) ⇒ BucketMaker::Bucket
Get the Bucket object when given the bucket_name.
-
#each_bucket ⇒ Object
Iterator going through each bucket.
-
#has_bucket?(bucket_name) ⇒ Boolean
Check if the Series has the bucket.
-
#has_group_in_bucket?(bucket_name, group_name) ⇒ Boolean
Check if the bucket has the group.
-
#initialize(name, options = {}) ⇒ Series
constructor
Initializer.
-
#is_bucketable?(bucketable) ⇒ Boolean
Check if the Bucketable object conforms to the conditions.
Constructor Details
#initialize(name, options = {}) ⇒ Series
Initializer
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bucket_maker/series.rb', line 19 def initialize(name, ={}) @name = name.to_sym @description = [SERIES_DESCRIPTION] || '' @created_after = if [SERIES_USER_AFTER] DateTime.parse([SERIES_USER_AFTER]) else DateTime.parse("1st Jan 1900") end @buckets = [SERIES_BUCKETS].inject({}) do |result, (bucket_name, )| result[bucket_name.to_sym] = BucketMaker::Bucket.new(bucket_name, ) result end if [SERIES_BUCKETS] end |
Instance Attribute Details
#buckets ⇒ Object (readonly)
Returns the value of attribute buckets.
5 6 7 |
# File 'lib/bucket_maker/series.rb', line 5 def buckets @buckets end |
#created_after ⇒ Object (readonly)
Returns the value of attribute created_after.
5 6 7 |
# File 'lib/bucket_maker/series.rb', line 5 def created_after @created_after end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/bucket_maker/series.rb', line 5 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/bucket_maker/series.rb', line 5 def name @name end |
Instance Method Details
#bucket_with_name(bucket_name) ⇒ BucketMaker::Bucket
Get the Bucket object when given the bucket_name
46 47 48 |
# File 'lib/bucket_maker/series.rb', line 46 def bucket_with_name(bucket_name) @buckets[bucket_name.to_sym] if bucket_name end |
#each_bucket ⇒ Object
Iterator going through each bucket
35 36 37 38 39 |
# File 'lib/bucket_maker/series.rb', line 35 def each_bucket @buckets.each do |bucket_name, bucket| yield bucket_name, bucket end if block_given? end |
#has_bucket?(bucket_name) ⇒ Boolean
Check if the Series has the bucket
64 65 66 |
# File 'lib/bucket_maker/series.rb', line 64 def has_bucket?(bucket_name) @buckets[bucket_name.to_sym] != nil rescue false end |
#has_group_in_bucket?(bucket_name, group_name) ⇒ Boolean
Check if the bucket has the group
74 75 76 |
# File 'lib/bucket_maker/series.rb', line 74 def has_group_in_bucket?(bucket_name, group_name) has_bucket?(bucket_name) && @buckets[bucket_name.to_sym].has_group?(group_name) rescue false end |
#is_bucketable?(bucketable) ⇒ Boolean
Check if the Bucketable object conforms to the conditions
55 56 57 |
# File 'lib/bucket_maker/series.rb', line 55 def is_bucketable?(bucketable) bucketable.created_at >= @created_after rescue false end |