Class: AwesomeBot::Result
- Inherits:
-
Object
- Object
- AwesomeBot::Result
- Defined in:
- lib/awesome_bot/result.rb
Overview
Result
Instance Attribute Summary collapse
-
#dupes ⇒ Object
Returns the value of attribute dupes.
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#links_white_listed ⇒ Object
readonly
Returns the value of attribute links_white_listed.
-
#skip_dupe ⇒ Object
Returns the value of attribute skip_dupe.
-
#status ⇒ Object
Returns the value of attribute status.
-
#white_listed ⇒ Object
Returns the value of attribute white_listed.
Instance Method Summary collapse
-
#initialize(links, white_list_from_cli) ⇒ Result
constructor
A new instance of Result.
- #statuses_issues(options = nil) ⇒ Object
- #success(options) ⇒ Object
- #success_dupe ⇒ Object
- #success_links(options) ⇒ Object
- #white_listing ⇒ Object
- #write(filename) ⇒ Object
- #write_artifacts ⇒ Object
Constructor Details
#initialize(links, white_list_from_cli) ⇒ Result
Returns a new instance of Result.
15 16 17 18 19 20 21 22 |
# File 'lib/awesome_bot/result.rb', line 15 def initialize(links, white_list_from_cli) @links = links @w = white_list_from_cli return if @w.nil? @links_white_listed, @links = links.partition { |u| AwesomeBot.white_list @w, u } end |
Instance Attribute Details
#dupes ⇒ Object
Returns the value of attribute dupes.
7 8 9 |
# File 'lib/awesome_bot/result.rb', line 7 def dupes @dupes end |
#links ⇒ Object (readonly)
Returns the value of attribute links.
13 14 15 |
# File 'lib/awesome_bot/result.rb', line 13 def links @links end |
#links_white_listed ⇒ Object (readonly)
Returns the value of attribute links_white_listed.
12 13 14 |
# File 'lib/awesome_bot/result.rb', line 12 def links_white_listed @links_white_listed end |
#skip_dupe ⇒ Object
Returns the value of attribute skip_dupe.
8 9 10 |
# File 'lib/awesome_bot/result.rb', line 8 def skip_dupe @skip_dupe end |
#status ⇒ Object
Returns the value of attribute status.
9 10 11 |
# File 'lib/awesome_bot/result.rb', line 9 def status @status end |
#white_listed ⇒ Object
Returns the value of attribute white_listed.
10 11 12 |
# File 'lib/awesome_bot/result.rb', line 10 def white_listed @white_listed end |
Instance Method Details
#statuses_issues(options = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/awesome_bot/result.rb', line 24 def statuses_issues(=nil) = { 'timeout'=>false, 'ssl'=>false, 'redirect'=>false } if .nil? s = status.select { |x| x['status'] != 200 } if ['timeout'] s = s.reject do |x| ( (x['error']. == 'Net::ReadTimeout') || (x['error']. == 'execution expired') || (x['error']..include? 'timed out') ) unless x['error'].nil? end end if ['redirect'] s = s.reject { |x| AwesomeBot.status_is_redirected? x['status'] } end if ['ssl'] s = s.reject do |x| ( (x['error']..include? 'server certificate') || (x['error']..include? 'SSL_connect') ) unless x['error'].nil? end end unless ['errors'].nil? ['errors'].each do |c| s = s.reject { |x| x['status']==c.to_i } end end s end |
#success(options) ⇒ Object
58 59 60 |
# File 'lib/awesome_bot/result.rb', line 58 def success() success_dupe && success_links() end |
#success_dupe ⇒ Object
62 63 64 65 |
# File 'lib/awesome_bot/result.rb', line 62 def success_dupe return true if skip_dupe links.uniq.count == links.count end |
#success_links(options) ⇒ Object
67 68 69 |
# File 'lib/awesome_bot/result.rb', line 67 def success_links() statuses_issues().count==0 end |
#white_listing ⇒ Object
71 72 73 |
# File 'lib/awesome_bot/result.rb', line 71 def white_listing !@w.nil? end |
#write(filename) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/awesome_bot/result.rb', line 75 def write(filename) require 'json' r = write_artifacts File.open(filename, 'w') { |f| f.write JSON.pretty_generate(r) } end |
#write_artifacts ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/awesome_bot/result.rb', line 82 def write_artifacts require 'date' { 'date'=>Time.now, 'links'=>@links, 'issues'=>statuses_issues, 'all'=>status } end |