Class: EDango::TicketExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/edango/logic/ticket_extractor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTicketExtractor

Returns a new instance of TicketExtractor.



24
25
26
27
28
29
30
31
32
# File 'lib/edango/logic/ticket_extractor.rb', line 24

def initialize
  @environment = SERVICES[:environment]
  @options = @environment.options

  @timer = SERVICES[:timer]
  @time_limit = @options[:time_limit]

  @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



22
23
24
# File 'lib/edango/logic/ticket_extractor.rb', line 22

def errors
  @errors
end

Instance Method Details

#extract_tickets(url, passkey, specs) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/edango/logic/ticket_extractor.rb', line 34

def extract_tickets(url, passkey, specs)
  result = []

  @errors = []
  @agent  = SERVICES[:agent, :init]

  specs.each do |spec|
    errors_root = @errors

    @errors << [spec.first]
    @errors = @errors.last

    begin
      @timer.timeout(@time_limit) do
        result += extract_ticket(url, passkey, spec)
      end
    rescue Timeout::Error => e
      @errors << t(:operation_timed_out)
    end

    @errors = errors_root
    @errors.pop() if @errors.last.size == 1
  end

  if specs.empty?
    @errors.unshift([t(:all_specs), t(:no_specs_for_url)])
  end

  result
end