Class: JustizSync::Transfer
- Inherits:
-
Object
- Object
- JustizSync::Transfer
- Defined in:
- lib/justiz_sync/cli.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
-
#initialize(options) ⇒ Transfer
constructor
A new instance of Transfer.
- #sync ⇒ Object
- #sync_all ⇒ Object
- #sync_courts(courts) ⇒ Object
- #sync_state(state) ⇒ Object
Constructor Details
#initialize(options) ⇒ Transfer
Returns a new instance of Transfer.
20 21 22 23 24 |
# File 'lib/justiz_sync/cli.rb', line 20 def initialize() = STDOUT.sync = true open_connection end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
19 20 21 |
# File 'lib/justiz_sync/cli.rb', line 19 def end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
19 20 21 |
# File 'lib/justiz_sync/cli.rb', line 19 def stream @stream end |
Instance Method Details
#sync ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/justiz_sync/cli.rb', line 26 def sync @stream = Stream.new delete_unused = false if (state = ['state']) sync_state(state) else sync_all delete_unused = true end stream.close(delete_unused) end |
#sync_all ⇒ Object
38 39 40 41 42 43 |
# File 'lib/justiz_sync/cli.rb', line 38 def sync_all states = scraper.states states.keys.each do |state| sync_state(state) end end |
#sync_courts(courts) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/justiz_sync/cli.rb', line 51 def sync_courts(courts) courts.each_with_index do |court, index| stream.sync(court) puts if verbose && index && (index % 20 == 0) putc('.') if verbose end puts if verbose end |
#sync_state(state) ⇒ Object
45 46 47 48 49 |
# File 'lib/justiz_sync/cli.rb', line 45 def sync_state(state) courts = scraper.contacts_for(state) puts "Syncing #{state} #{courts.length} courts" sync_courts(courts) end |