Class: Defoker::Core
- Inherits:
-
Object
- Object
- Defoker::Core
- Defined in:
- lib/defoker_core.rb
Overview
Defoker Core
Class Method Summary collapse
-
.days(date, count: 3, additional: '') ⇒ String
Get days folder name list.
-
.init ⇒ Object
Generate Defokerfile template.
-
.months(month, count: 3, additional: '') ⇒ String
Get months folder name list.
-
.mv_month ⇒ Object
Move YYYYMMDD_somename format folder to YYYYMM folder.
-
.mv_year ⇒ Object
Move YYYYMM_somename format folder to YYYY folder.
-
.next_month(additional: '') ⇒ String
Get next month folder name.
-
.next_year(additional: '') ⇒ String
Get next year folder name.
-
.previous_month(additional: '') ⇒ String
Get previous month folder name.
-
.previous_year(additional: '') ⇒ String
Get previous year folder name.
-
.rule(additional: '') ⇒ String
Create folder by Defokerfile’s rule.
-
.this_month(additional: '') ⇒ String
Get this month folder name.
-
.this_year(additional: '') ⇒ String
Get this year folder name.
-
.today(additional: '') ⇒ String
Get today folder name.
-
.tomorrow(additional: '') ⇒ String
Get tomorrow folder name.
-
.years(year, count: 3, additional: '') ⇒ String
Get years folder name list.
-
.yesterday(additional: '') ⇒ String
Get yesterday folder name.
Class Method Details
.days(date, count: 3, additional: '') ⇒ String
Get days folder name list
72 73 74 75 |
# File 'lib/defoker_core.rb', line 72 def self.days(date, count: 3, additional: '') date = Date.new(date[0..3].to_i, date[4..5].to_i, date[6..7].to_i) DateBaseName.to_yyyymmdd_list(date, count: count, additional: additional) end |
.init ⇒ Object
Generate Defokerfile template
39 40 41 |
# File 'lib/defoker_core.rb', line 39 def self.init File.open(DEFOKERFILE_PATH, 'w:utf-8') { |f|f.puts DEFOKERFILE_TEMPLATE } end |
.months(month, count: 3, additional: '') ⇒ String
Get months folder name list
106 107 108 109 |
# File 'lib/defoker_core.rb', line 106 def self.months(month, count: 3, additional: '') month = Date.new(month[0..3].to_i, month[4..5].to_i) DateBaseName.to_yyyymm_list(month, count: count, additional: additional) end |
.mv_month ⇒ Object
Move YYYYMMDD_somename format folder to YYYYMM folder.
160 161 162 163 164 165 166 167 168 |
# File 'lib/defoker_core.rb', line 160 def self.mv_month Dir.glob('*/').each do |dir| next unless dir =~ %r(^[0-9]{8}(_.*)*/$) month_dir = dir[0, 6] FileUtils.mkdir_p(month_dir) unless Dir.exist?(month_dir) day_dir = dir[6..-1] FileUtils.mv(dir, File.join(month_dir, day_dir)) end end |
.mv_year ⇒ Object
Move YYYYMM_somename format folder to YYYY folder.
172 173 174 175 176 177 178 179 180 |
# File 'lib/defoker_core.rb', line 172 def self.mv_year Dir.glob('*/').each do |dir| next unless dir =~ %r(^[0-9]{6}(_.*)*/$) year_dir = dir[0, 4] FileUtils.mkdir_p(year_dir) unless Dir.exist?(year_dir) month_dir = dir[4..-1] FileUtils.mv(dir, File.join(year_dir, month_dir)) end end |
.next_month(additional: '') ⇒ String
Get next month folder name
89 90 91 |
# File 'lib/defoker_core.rb', line 89 def self.next_month(additional: '') DateBaseName.to_yyyymm(Date.today >> 1, additional: additional) end |
.next_year(additional: '') ⇒ String
Get next year folder name
123 124 125 |
# File 'lib/defoker_core.rb', line 123 def self.next_year(additional: '') DateBaseName.to_yyyy(Date.today >> 12, additional: additional) end |
.previous_month(additional: '') ⇒ String
Get previous month folder name
97 98 99 |
# File 'lib/defoker_core.rb', line 97 def self.previous_month(additional: '') DateBaseName.to_yyyymm(Date.today << 1, additional: additional) end |
.previous_year(additional: '') ⇒ String
Get previous year folder name
131 132 133 |
# File 'lib/defoker_core.rb', line 131 def self.previous_year(additional: '') DateBaseName.to_yyyy(Date.today << 12, additional: additional) end |
.rule(additional: '') ⇒ String
Create folder by Defokerfile’s rule.
149 150 151 152 153 154 155 156 |
# File 'lib/defoker_core.rb', line 149 def self.rule(additional: '') dsl = read_dsl base = dsl.defoker.base callback = dsl.defoker.callback adds = [base, additional].reject(&:empty?) dir = send(dsl.defoker.type, additional: adds.join('_')) [dir, callback] end |
.this_month(additional: '') ⇒ String
Get this month folder name
81 82 83 |
# File 'lib/defoker_core.rb', line 81 def self.this_month(additional: '') DateBaseName.to_yyyymm(Date.today, additional: additional) end |
.this_year(additional: '') ⇒ String
Get this year folder name
115 116 117 |
# File 'lib/defoker_core.rb', line 115 def self.this_year(additional: '') DateBaseName.to_yyyy(Date.today, additional: additional) end |
.today(additional: '') ⇒ String
Get today folder name
47 48 49 |
# File 'lib/defoker_core.rb', line 47 def self.today(additional: '') DateBaseName.to_yyyymmdd(Date.today, additional: additional) end |
.tomorrow(additional: '') ⇒ String
Get tomorrow folder name
55 56 57 |
# File 'lib/defoker_core.rb', line 55 def self.tomorrow(additional: '') DateBaseName.to_yyyymmdd(Date.today + 1, additional: additional) end |
.years(year, count: 3, additional: '') ⇒ String
Get years folder name list
140 141 142 143 |
# File 'lib/defoker_core.rb', line 140 def self.years(year, count: 3, additional: '') year = Date.new(year[0..3].to_i) DateBaseName.to_yyyy_list(year, count: count, additional: additional) end |
.yesterday(additional: '') ⇒ String
Get yesterday folder name
63 64 65 |
# File 'lib/defoker_core.rb', line 63 def self.yesterday(additional: '') DateBaseName.to_yyyymmdd(Date.today - 1, additional: additional) end |