Class: Apt::Spy2::Writer
- Inherits:
-
Object
- Object
- Apt::Spy2::Writer
- Defined in:
- lib/apt/spy2/writer.rb
Instance Method Summary collapse
- #echo(data) ⇒ Object
-
#initialize(format) ⇒ Writer
constructor
A new instance of Writer.
- #json? ⇒ Boolean
- #set_complete(complete) ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(format) ⇒ Writer
Returns a new instance of Writer.
7 8 9 10 11 12 13 14 15 |
# File 'lib/apt/spy2/writer.rb', line 7 def initialize(format) if !["json", "shell"].include?(format) raise "Unknown format: #{format}" end @format = format @complete = [] end |
Instance Method Details
#echo(data) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/apt/spy2/writer.rb', line 21 def echo(data) if @format == 'json' @complete.push(data) return end print "Mirror: #{data["mirror"]} - " case data["status"] when "up" puts data["status"].upcase.green when "down" puts data["status"].upcase.red when "broken" puts data["status"].upcase.yellow else puts "Unknown status: #{data["status"]}".white_on_red end end |
#json? ⇒ Boolean
41 42 43 44 45 46 47 |
# File 'lib/apt/spy2/writer.rb', line 41 def json? if @format == 'json' return true end return false end |
#set_complete(complete) ⇒ Object
17 18 19 |
# File 'lib/apt/spy2/writer.rb', line 17 def set_complete(complete) @complete = complete end |
#to_json ⇒ Object
49 50 51 |
# File 'lib/apt/spy2/writer.rb', line 49 def to_json JSON.generate(@complete) end |