Class: IdsPlease::Grabbers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ids_please/grabbers/base.rb

Direct Known Subclasses

Facebook, GooglePlus, Instagram, Mailru, Twitter, Vkontakte

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(link) ⇒ Base

Returns a new instance of Base.



20
21
22
# File 'lib/ids_please/grabbers/base.rb', line 20

def initialize(link)
  @link = link
end

Instance Attribute Details

#avatarObject (readonly)

Returns the value of attribute avatar.



11
12
13
# File 'lib/ids_please/grabbers/base.rb', line 11

def avatar
  @avatar
end

#countsObject (readonly)

Returns the value of attribute counts.



11
12
13
# File 'lib/ids_please/grabbers/base.rb', line 11

def counts
  @counts
end

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/ids_please/grabbers/base.rb', line 11

def data
  @data
end

#display_nameObject (readonly)

Returns the value of attribute display_name.



11
12
13
# File 'lib/ids_please/grabbers/base.rb', line 11

def display_name
  @display_name
end

Returns the value of attribute link.



11
12
13
# File 'lib/ids_please/grabbers/base.rb', line 11

def link
  @link
end

#network_idObject (readonly)

Returns the value of attribute network_id.



11
12
13
# File 'lib/ids_please/grabbers/base.rb', line 11

def network_id
  @network_id
end

#page_sourceObject (readonly)

Returns the value of attribute page_source.



11
12
13
# File 'lib/ids_please/grabbers/base.rb', line 11

def page_source
  @page_source
end

#usernameObject (readonly)

Returns the value of attribute username.



11
12
13
# File 'lib/ids_please/grabbers/base.rb', line 11

def username
  @username
end

Class Method Details

.interact(links) ⇒ Object



7
8
9
# File 'lib/ids_please/grabbers/base.rb', line 7

def self.interact(links)
  links.map { |l| self.new(l).grab_link }
end

Instance Method Details

#errorsObject



59
60
61
# File 'lib/ids_please/grabbers/base.rb', line 59

def errors
  @errors ||= []
end

#find_by_regex(reg) ⇒ Object



67
68
69
# File 'lib/ids_please/grabbers/base.rb', line 67

def find_by_regex(reg)
  page_source.scan(reg).flatten.first
end


24
25
26
# File 'lib/ids_please/grabbers/base.rb', line 24

def grab_link(_link)
  throw 'Base grabber can not grab anything'
end

#inspectObject



51
52
53
# File 'lib/ids_please/grabbers/base.rb', line 51

def inspect
  to_s
end

#record_error(event, message) ⇒ Object



63
64
65
# File 'lib/ids_please/grabbers/base.rb', line 63

def record_error(event, message)
  errors << "#{event} has #{message}"
end

#to_hObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ids_please/grabbers/base.rb', line 39

def to_h
  {
    avatar: avatar,
    display_name: display_name,
    username: username,
    link: link,
    page_source: page_source,
    network_id: network_id,
    data: data
  }
end

#to_sObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/ids_please/grabbers/base.rb', line 28

def to_s
  line = ''
  self.instance_variables.each do |iv|
    next if iv == :@page_source
    val = self.instance_variable_get(iv)
    next if val.nil? || val == ''
    line += ", \n#{iv}=#{val}"
  end
  "#{self.class}##{self.object_id} #{line[1..-1]}"
end