Class: BucketMaker::Series

Inherits:
Object
  • Object
show all
Defined in:
lib/bucket_maker/series.rb

Constant Summary collapse

SERIES_DESCRIPTION =
'description'
SERIES_USER_AFTER =
'created_after'
SERIES_BUCKETS =
'buckets'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Series

Returns a new instance of Series.



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bucket_maker/series.rb', line 12

def initialize(name, options={})
  @name = name.to_sym
  @description = options[SERIES_DESCRIPTION] || ''
  @created_after =  if options[SERIES_USER_AFTER]
                            DateTime.parse(options[SERIES_USER_AFTER])
                          else
                            DateTime.parse("1st Jan 1900")
                          end
  @buckets =  options[SERIES_BUCKETS].inject({}) do |result, (bucket_name, bucket_options)|
                result[bucket_name.to_sym] = BucketMaker::Bucket.new(bucket_name, bucket_options)
                result
              end if options[SERIES_BUCKETS]
end

Instance Attribute Details

#bucketsObject (readonly)

Returns the value of attribute buckets.



3
4
5
# File 'lib/bucket_maker/series.rb', line 3

def buckets
  @buckets
end

#created_afterObject (readonly)

Returns the value of attribute created_after.



3
4
5
# File 'lib/bucket_maker/series.rb', line 3

def created_after
  @created_after
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/bucket_maker/series.rb', line 3

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/bucket_maker/series.rb', line 3

def name
  @name
end

Instance Method Details

#bucket_with_name(bucket_name) ⇒ Object



32
33
34
# File 'lib/bucket_maker/series.rb', line 32

def bucket_with_name(bucket_name)
  @buckets[bucket_name.to_sym]
end

#each_bucketObject



26
27
28
29
30
# File 'lib/bucket_maker/series.rb', line 26

def each_bucket
  @buckets.each do |bucket_name, bucket|
    yield bucket_name, bucket
  end if block_given?
end

#has_bucket?(bucket_name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/bucket_maker/series.rb', line 40

def has_bucket?(bucket_name)
  @buckets[bucket_name.to_sym] != nil
end

#has_group_in_bucket?(bucket_name, group_name) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/bucket_maker/series.rb', line 44

def has_group_in_bucket?(bucket_name, group_name)
  has_bucket?(bucket_name) && @buckets[bucket_name.to_sym].has_group?(group_name)
end

#is_bucketable?(bucketable) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/bucket_maker/series.rb', line 36

def is_bucketable?(bucketable)
  bucketable.created_at >= @created_after
end