Class: Devlog::Day

Inherits:
Object
  • Object
show all
Includes:
SevendaysTotal
Defined in:
lib/devlog.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SevendaysTotal

#total_hours, #total_hours_string

Constructor Details

#initialize(day, zezzions) ⇒ Day

Returns a new instance of Day.



346
347
348
349
# File 'lib/devlog.rb', line 346

def initialize(day, zezzions)
  @all = zezzions.sort # sorting by default by zzbegin
  @day = Sevendays::DAYS.include?(day) ? day : Sevendays::RANDOMDAY
end

Instance Attribute Details

#allObject

Returns the value of attribute all.



343
344
345
# File 'lib/devlog.rb', line 343

def all
  @all
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


355
356
357
# File 'lib/devlog.rb', line 355

def any?
  all.any?
end

#begins_atObject



359
360
361
362
# File 'lib/devlog.rb', line 359

def begins_at
  return '' unless any?
  all.first.zzbegin.strftime('%H:%M')
end

#breaks_atObject



369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'lib/devlog.rb', line 369

def breaks_at
  return '' unless any?

  size = all.size

  return "" if size < 2

  breaks = []
  first = true
  last = nil

  all.each do |zezzion|
    if first
      last = zezzion
      first = false
    else
      breaks << "#{last.zzend.strftime('%H:%M')} -> #{zezzion.zzbegin.strftime('%H:%M')}"
      last = zezzion
    end
  end

  breaks.join(', ')
end

#ends_atObject



364
365
366
367
# File 'lib/devlog.rb', line 364

def ends_at
  return '' unless any?
  all.last.zzend.strftime("%H:%M")
end

#nameObject



351
352
353
# File 'lib/devlog.rb', line 351

def name
  @day
end