Class: SweetyBacky::Utils
- Inherits:
-
Object
- Object
- SweetyBacky::Utils
- Defined in:
- lib/sweety_backy/utils.rb
Class Method Summary collapse
- .command(_command) ⇒ Object
- .is_last_day_of_month? ⇒ Boolean
- .is_last_day_of_week? ⇒ Boolean
- .is_last_day_of_year? ⇒ Boolean
- .log(msg) ⇒ Object
- .namerize(path) ⇒ Object
- .period ⇒ Object
Class Method Details
.command(_command) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/sweety_backy/utils.rb', line 23 def self.command( _command ) Utils.log "command: #{_command}" result = system(_command) raise "ERROR: on command: '#{_command}', result: '#{result}'" if !result end |
.is_last_day_of_month? ⇒ Boolean
15 16 17 |
# File 'lib/sweety_backy/utils.rb', line 15 def self.is_last_day_of_month? return Date.new(Date.today.year, Date.today.month, -1) == Date.today end |
.is_last_day_of_week? ⇒ Boolean
19 20 21 |
# File 'lib/sweety_backy/utils.rb', line 19 def self.is_last_day_of_week? return Date.today.cwday == 7 end |
.is_last_day_of_year? ⇒ Boolean
11 12 13 |
# File 'lib/sweety_backy/utils.rb', line 11 def self.is_last_day_of_year? return Date.new(Date.today.year, 12, -1) == Date.today end |
.log(msg) ⇒ Object
31 32 33 |
# File 'lib/sweety_backy/utils.rb', line 31 def self.log( msg ) puts "#{Time.now.strftime("%Y-%m-%d %H:%M")}: #{msg}" end |
.namerize(path) ⇒ Object
35 36 37 |
# File 'lib/sweety_backy/utils.rb', line 35 def self.namerize( path ) path.gsub('/', '.').gsub(/^\./, '') end |
.period ⇒ Object
4 5 6 7 8 9 |
# File 'lib/sweety_backy/utils.rb', line 4 def self.period return 'yearly' if( is_last_day_of_year? ) return 'monthly' if( is_last_day_of_month? ) return 'weekly' if( is_last_day_of_week? ) return 'daily' end |