Class: LibPtgBox::Product

Inherits:
Object
  • Object
show all
Defined in:
app/modules/lib_ptg_box/product.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product_family, kbart_file) ⇒ Product

rubocop:disable Metrics/AbcSize


7
8
9
10
11
12
13
14
15
16
17
# File 'app/modules/lib_ptg_box/product.rb', line 7

def initialize(product_family, kbart_file) # rubocop:disable Metrics/AbcSize
  @product_family = product_family
  @kbart_file = kbart_file
  match = /(^.+)_(\d{4})(.*)?_(\d{4})-(\d{2})-(\d{2})\.(.+$)/.match(@kbart_file.name)
  @name = match[1] + '_' + match[2] + match[3]
  @year = match[2]
  @suffix = match[3]
  @yyyy = match[4]
  @mm = match[5]
  @dd = match[6]
end

Instance Attribute Details

#ddObject (readonly)

Returns the value of attribute dd


5
6
7
# File 'app/modules/lib_ptg_box/product.rb', line 5

def dd
  @dd
end

#mmObject (readonly)

Returns the value of attribute mm


5
6
7
# File 'app/modules/lib_ptg_box/product.rb', line 5

def mm
  @mm
end

#nameObject (readonly)

Returns the value of attribute name


5
6
7
# File 'app/modules/lib_ptg_box/product.rb', line 5

def name
  @name
end

#product_familyObject (readonly)

Returns the value of attribute product_family


5
6
7
# File 'app/modules/lib_ptg_box/product.rb', line 5

def product_family
  @product_family
end

#yearObject (readonly)

Returns the value of attribute year


5
6
7
# File 'app/modules/lib_ptg_box/product.rb', line 5

def year
  @year
end

#yyyyObject (readonly)

Returns the value of attribute yyyy


5
6
7
# File 'app/modules/lib_ptg_box/product.rb', line 5

def yyyy
  @yyyy
end

Instance Method Details

#modified_this_month?Boolean


31
32
33
# File 'app/modules/lib_ptg_box/product.rb', line 31

def modified_this_month?
  modified_this_year? && /#{@mm}/.match?(format("%02d", Time.now.month))
end

#modified_this_year?Boolean


35
36
37
# File 'app/modules/lib_ptg_box/product.rb', line 35

def modified_this_year?
  /#{@yyyy}/.match?(format("%04d", Time.now.year))
end

#modified_today?Boolean


27
28
29
# File 'app/modules/lib_ptg_box/product.rb', line 27

def modified_today?
  modified_this_year? && modified_this_month? && /#{@dd}/.match?(format("%02d", Time.now.day))
end

#worksObject


19
20
21
# File 'app/modules/lib_ptg_box/product.rb', line 19

def works
  @works ||= @kbart_file.kbarts.map { |kbart| Work.new(self, kbart) }
end

#year?Boolean


23
24
25
# File 'app/modules/lib_ptg_box/product.rb', line 23

def year?
  /#{@year}/.match?(format("%04d", Time.now.year))
end