Class: JustizSync::Transfer

Inherits:
Object
  • Object
show all
Defined in:
lib/justiz_sync/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Transfer



25
26
27
28
29
# File 'lib/justiz_sync/cli.rb', line 25

def initialize(options)
  @options = options
  STDOUT.sync = true
  open_connection
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



24
25
26
# File 'lib/justiz_sync/cli.rb', line 24

def options
  @options
end

Instance Method Details

#syncObject



31
32
33
34
35
36
37
38
# File 'lib/justiz_sync/cli.rb', line 31

def sync
  states = scraper.states
  total = 0
  states.keys.each do |state|
    total += sync_state(state)
  end
  puts "Total #{total} synchronized"
end

#sync_courts(courts) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/justiz_sync/cli.rb', line 47

def sync_courts(courts)
  courts.each_with_index do |court, index|
    OpencrxCourt.sync(court)
    puts if verbose && index && (index % 20 == 0)
    putc('.') if verbose
  end
  puts if verbose
end

#sync_state(state) ⇒ Object



40
41
42
43
44
45
# File 'lib/justiz_sync/cli.rb', line 40

def sync_state(state)
  courts = scraper.contacts_for(state)
  puts "Syncing #{state} #{courts.length} courts"
  sync_courts(courts)
  courts.length
end