class Berichtsheft::Activities

Holds information for activities in an array of hashes.

Attributes

all[R]
id_for_week[R]

Public Class Methods

new(data, id_for_week) click to toggle source
# File lib/berichtsheft/activities.rb, line 9
def initialize(data, id_for_week)
  @all = for_week(data, id_for_week)
  @id_for_week = id_for_week
end

Public Instance Methods

convert_string_to_time(time) click to toggle source
# File lib/berichtsheft/activities.rb, line 156
def convert_string_to_time(time)
  minutes = time[3..4].to_i
  hours = time[0..1].to_i
  total_minutes = (hours * 60) + minutes
  total_minutes * 60
end
end_date() click to toggle source
# File lib/berichtsheft/activities.rb, line 29
def end_date
  last_entry = @all.count - 1
  format_date(@all[last_entry]["date"])
end
for_friday() click to toggle source
# File lib/berichtsheft/activities.rb, line 89
def for_friday
  friday = []

  @all.each do |entry|
    if Date.parse(entry["date"]).friday?
      friday.push(entry)
    end
  end

  friday
end
for_monday() click to toggle source
# File lib/berichtsheft/activities.rb, line 41
def for_monday
  monday = []

  @all.each do |entry|
    if Date.parse(entry["date"]).monday?
      monday.push(entry)
    end
  end

  monday
end
for_thursday() click to toggle source
# File lib/berichtsheft/activities.rb, line 77
def for_thursday
  thursday = []

  @all.each do |entry|
    if Date.parse(entry["date"]).thursday?
      thursday.push(entry)
    end
  end

  thursday
end
for_tuesday() click to toggle source
# File lib/berichtsheft/activities.rb, line 53
def for_tuesday
  tuesday = []

  @all.each do |entry|
    if Date.parse(entry["date"]).tuesday?
      tuesday.push(entry)
    end
  end

  tuesday
end
for_wednesday() click to toggle source
# File lib/berichtsheft/activities.rb, line 65
def for_wednesday
  wednesday = []

  @all.each do |entry|
    if Date.parse(entry["date"]).wednesday?
      wednesday.push(entry)
    end
  end

  wednesday
end
for_week(data, id_for_week) click to toggle source
# File lib/berichtsheft/activities.rb, line 14
def for_week(data, id_for_week)
  activities_for_week = []
  data.each do |activity|
    if id_for_week == activity["id_for_week"]
      activities_for_week.push(activity)
    end
  end

  activities_for_week
end
format_date(date) click to toggle source
# File lib/berichtsheft/activities.rb, line 34
def format_date(date)
  day = date[8..10]
  month = date[5..6]
  year = date[0..3]
  "#{day}.#{month}.#{year}"
end
start_date() click to toggle source
# File lib/berichtsheft/activities.rb, line 25
def start_date
  format_date(@all[0]["date"])
end
total_time_friday() click to toggle source
# File lib/berichtsheft/activities.rb, line 145
def total_time_friday
  if for_friday
    time = 0
    for_friday.each do |activity|
      time += convert_string_to_time(activity["duration"])
    end
  end

  Time.at(time).utc.strftime("%H:%M")
end
total_time_monday() click to toggle source
# File lib/berichtsheft/activities.rb, line 101
def total_time_monday
  if for_monday
    time = 0
    for_monday.each do |activity|
      time += convert_string_to_time(activity["duration"])
    end
  end

  Time.at(time).utc.strftime("%H:%M")
end
total_time_thursday() click to toggle source
# File lib/berichtsheft/activities.rb, line 134
def total_time_thursday
  if for_thursday
    time = 0
    for_thursday.each do |activity|
      time += convert_string_to_time(activity["duration"])
    end
  end

  Time.at(time).utc.strftime("%H:%M")
end
total_time_tuesday() click to toggle source
# File lib/berichtsheft/activities.rb, line 112
def total_time_tuesday
  if for_tuesday
    time = 0
    for_tuesday.each do |activity|
      time += convert_string_to_time(activity["duration"])
    end
  end

  Time.at(time).utc.strftime("%H:%M")
end
total_time_wednesday() click to toggle source
# File lib/berichtsheft/activities.rb, line 123
def total_time_wednesday
  if for_wednesday
    time = 0
    for_wednesday.each do |activity|
      time += convert_string_to_time(activity["duration"])
    end
  end

  Time.at(time).utc.strftime("%H:%M")
end