Class: TelegramMeetupBot::Calendar

Inherits:
Object
  • Object
show all
Defined in:
lib/telegram_meetup_bot/calendar.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Calendar

Returns a new instance of Calendar.



5
6
7
8
9
10
# File 'lib/telegram_meetup_bot/calendar.rb', line 5

def initialize(args)
  @storage = Initializers::ConfigLoader.storage
  @date = args.fetch(:date)
  @user = args.fetch(:user)
  @time = args[:time]
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



3
4
5
# File 'lib/telegram_meetup_bot/calendar.rb', line 3

def date
  @date
end

#storageObject (readonly)

Returns the value of attribute storage.



3
4
5
# File 'lib/telegram_meetup_bot/calendar.rb', line 3

def storage
  @storage
end

#timeObject (readonly)

Returns the value of attribute time.



3
4
5
# File 'lib/telegram_meetup_bot/calendar.rb', line 3

def time
  @time
end

#userObject (readonly)

Returns the value of attribute user.



3
4
5
# File 'lib/telegram_meetup_bot/calendar.rb', line 3

def user
  @user
end

Class Method Details

.formated_users_for_date(date) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/telegram_meetup_bot/calendar.rb', line 31

def self.formated_users_for_date(date)
  storage = Initializers::ConfigLoader.storage
  users = storage.get_users_for_date(date)
  users.map! do |user|
    username = user[:username] ? " @#{user[:username]}" : ''
    "#{user[:first_name]}#{username} #{user[:time]}"
  end
  users.join("\n")
end

.submited_days_of_month(month) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/telegram_meetup_bot/calendar.rb', line 41

def self.submited_days_of_month(month)
  storage = Initializers::ConfigLoader.storage
  dates = storage.get_all_available_dates
  min, max = build_date_window(month)

  dates.keep_if { |date| date >= min && date <= max }.sort.
    map { |date| date.match(/\d\d$/) }.join(', ')
end

Instance Method Details

#add_user_to_dateObject



12
13
14
15
16
17
18
19
# File 'lib/telegram_meetup_bot/calendar.rb', line 12

def add_user_to_date
  process_user do |users, saved_user|
    return if saved_user == user_hash
    users.delete(saved_user) if saved_user
    users << user_hash
    storage.set_users_to_date(users, date)
  end
end

#delete_user_from_dateObject



21
22
23
24
25
26
27
28
29
# File 'lib/telegram_meetup_bot/calendar.rb', line 21

def delete_user_from_date
  process_user do |users, saved_user|
    if saved_user
      users.delete(saved_user)
      update_or_clean_date(users)
      true
    end
  end
end