Class: DailyRep::IBrowser

Inherits:
Object
  • Object
show all
Includes:
Dbops, Trackable
Defined in:
lib/dailyrep/IBrowser.rb

Constant Summary collapse

@@notificators =
Notificator.get_clients
@@index_writer =
IndexWriter.new
@@app_cycle_methods =
['process', 'write_to_db', 'web_reload', 'notify']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Trackable

#log_error, #log_msg

Methods included from Dbops

#check_history_notif, #check_row_exists, #write_hist

Constructor Details

#initialize(*inputs) ⇒ IBrowser

Returns a new instance of IBrowser.



21
22
23
# File 'lib/dailyrep/IBrowser.rb', line 21

def initialize *inputs
  @entity = self.class.to_s.downcase.split('::').last
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/dailyrep/IBrowser.rb', line 56

def method_missing(meth, *args, &block)
  if @@app_cycle_methods.include?(meth.to_s)
    begin
      self.log_msg meth.to_s
      block.call
      rescue Exception => e
        log_error e
    end
  else
    super
  end
end

Instance Attribute Details

#entityObject (readonly)

Returns the value of attribute entity.



15
16
17
# File 'lib/dailyrep/IBrowser.rb', line 15

def entity
  @entity
end

Class Method Details

.write_htmlObject



40
41
42
# File 'lib/dailyrep/IBrowser.rb', line 40

def self.write_html
  @@index_writer.write_html
end

Instance Method Details

#get_source_http(source, val_scope) ⇒ Object



45
46
47
48
# File 'lib/dailyrep/IBrowser.rb', line 45

def get_source_http source, val_scope
  page = Nokogiri::HTML(open(source.to_s))
  page.css(val_scope)
end

#get_source_json(source) ⇒ Object



50
51
52
53
54
# File 'lib/dailyrep/IBrowser.rb', line 50

def get_source_json source
  uri = URI(source)
  out_json = Net::HTTP.get(uri)
  JSON.parse(out_json)
end

#push_note(note) ⇒ Object



25
26
27
28
29
30
# File 'lib/dailyrep/IBrowser.rb', line 25

def push_note note
  @@notificators.each { |client|
    client.push_note(note)
  }
  # @@client.push_note(nil, @@note_title,  note)
end

#runObject



69
70
71
72
73
74
# File 'lib/dailyrep/IBrowser.rb', line 69

def run
  self.process
  self.write_to_db if Configer.is_phase_enabled?('write_to_db')
  self.notify if Configer.is_phase_enabled?('notify')
  self.web_reload if Configer.is_phase_enabled?('web_reload')
end

#set_html(entity, values, push = 0) ⇒ Object



32
33
34
# File 'lib/dailyrep/IBrowser.rb', line 32

def set_html entity, values, push=0
  @@index_writer.set_html entity, values, push
end

#set_html_with_diff(entity, scope, diff, reset = false) ⇒ Object



36
37
38
# File 'lib/dailyrep/IBrowser.rb', line 36

def set_html_with_diff entity, scope, diff, reset=false
  @@index_writer.set_html_with_diff entity, scope, diff, reset
end