Class: BucketMaker::Series

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

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

Initializer

Parameters:

  • name (String)

    Name of the Series

  • options (Hash) (defaults to: {})

    Options for the Series like SERIES_DESCRIPTION, SERIES_USER_AFTER, SERIES_BUCKETS



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bucket_maker/series.rb', line 19

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.



5
6
7
# File 'lib/bucket_maker/series.rb', line 5

def buckets
  @buckets
end

#created_afterObject (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

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/bucket_maker/series.rb', line 5

def description
  @description
end

#nameObject (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

Parameters:

  • bucket_name (String)

    Name of the Bucket

Returns:



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_bucketObject

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

Parameters:

  • bucket_name (String)

    Name of the Bucket

Returns:

  • (Boolean)

    does the bucket exist?



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

Parameters:

  • bucket_name (String)

    Name of the Bucket

  • group_name (String)

    Name of the Group

Returns:

  • (Boolean)

    does the group exist inside the bucket?



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

Parameters:

  • bucketable (Object)

    an object which responds to :created_at

Returns:

  • (Boolean)

    is it bucketable?



55
56
57
# File 'lib/bucket_maker/series.rb', line 55

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