Class: Standupguy::Item

Inherits:
Object
  • Object
show all
Includes:
DataMethods
Defined in:
lib/Standupguy.rb

Overview

Basic Item class. Each line in your standup is an Item.

Defined Under Namespace

Classes: TicketUrl

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DataMethods

#date_key, #filename, #load_data, #write_data

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



178
179
180
181
182
183
# File 'lib/Standupguy.rb', line 178

def method_missing(method, *args)
  method_list = [:description=, :name=, :date=, :ticket_id=]
  return unless method_list.include?(method)
  method = method.to_s.chop.to_sym
  @data[method] = args.first
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



176
177
178
# File 'lib/Standupguy.rb', line 176

def data
  @data
end

Instance Method Details

#add_to_today(item) ⇒ Object



214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/Standupguy.rb', line 214

def add_to_today(item)
  @data ||= { description: "", date: "", ticket_id: false }
  ticket = TicketUrl.new(item)
  if ticket.valid?
    zendesk_ticket = client(ticket.subdomain).tickets.find(id: ticket.id)
    self.ticket_id = item
    self.description = "#{item} => (#{zendesk_ticket.subject})"
  else
    self.description = item
  end

  self.name = `whoami`.chop
  self.date = key
end

#client(subdomain) ⇒ Object



229
230
231
232
233
234
235
# File 'lib/Standupguy.rb', line 229

def client(subdomain)
  @client ||= ZendeskAPI::Client.new do |config|
    config.url = "https://#{subdomain}.zendesk.com/api/v2"
    config.username = ENV["zendesk_user"]
    config.token = ENV["zendesk_token"]
  end
end

#continue?Boolean

Returns:

  • (Boolean)


185
186
187
188
189
190
# File 'lib/Standupguy.rb', line 185

def continue?
  puts "This ticket has already been added. Do you want to continue adding it? (y/N)\n  EOS\n  STDIN.gets.downcase.chomp[0] == \"y\"\nend\n"

#saveObject



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/Standupguy.rb', line 192

def save
  current_standup = load_data
  current_standup ||= { date_key => [] }
  data_exists = current_standup.keys.include?(date_key)
  begin
    if data_exists && !!@data[:ticket_id]
      ticket_list = current_standup[date_key]
      ticket_list.map! { |item| item["ticket_id"] }
      unless ticket_list.empty?
        already_added = ticket_list.include?(@data[:ticket_id])
        raise "Already added" if already_added
      end
    end
  rescue RuntimeError
    return unless continue?
  end

  current_standup[date_key] ||= []
  current_standup[date_key] << @data
  write_data(current_standup)
end