Class: Ayadn::Preferences

Inherits:
Object show all
Defined in:
lib/ayadn/preferences_object.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Preferences

Returns a new instance of Preferences.



227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/ayadn/preferences_object.rb', line 227

def initialize hash
  @source_hash = hash
  @timeline = PreferencesTimeline.new(hash[:timeline])
  @marker = PreferencesMarker.new(hash[:marker])
  @counts = PreferencesCounts.new(hash[:counts])
  @formats = PreferencesFormats.new(hash[:formats])
  @channels = PreferencesChannels.new(hash[:channels])
  @colors = PreferencesColors.new(hash[:colors])
  @backup = PreferencesBackup.new(hash[:backup])
  @scroll = PreferencesScroll.new(hash[:scroll])
  @nicerank = PreferencesNicerank.new(hash[:nicerank])
  @nowplaying = {}
  @blacklist = PreferencesBlacklist.new(hash[:blacklist])
end

Instance Attribute Details

#backupObject

Returns the value of attribute backup.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def backup
  @backup
end

#blacklistObject

Returns the value of attribute blacklist.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def blacklist
  @blacklist
end

#channelsObject

Returns the value of attribute channels.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def channels
  @channels
end

#colorsObject

Returns the value of attribute colors.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def colors
  @colors
end

#countsObject

Returns the value of attribute counts.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def counts
  @counts
end

#formatsObject

Returns the value of attribute formats.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def formats
  @formats
end

#markerObject

Returns the value of attribute marker.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def marker
  @marker
end

#nicerankObject

Returns the value of attribute nicerank.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def nicerank
  @nicerank
end

#nowplayingObject

Returns the value of attribute nowplaying.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def nowplaying
  @nowplaying
end

#scrollObject

Returns the value of attribute scroll.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def scroll
  @scroll
end

#source_hashObject

Returns the value of attribute source_hash.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def source_hash
  @source_hash
end

#timelineObject

Returns the value of attribute timeline.



225
226
227
# File 'lib/ayadn/preferences_object.rb', line 225

def timeline
  @timeline
end

Instance Method Details

#to_hObject



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/ayadn/preferences_object.rb', line 242

def to_h
  {
    timeline: @timeline.to_h,
    marker: @marker.to_h,
    counts: @counts.to_h,
    formats: @formats.to_h,
    channels: @channels.to_h,
    colors: @colors.to_h,
    backup: @backup.to_h,
    scroll: @scroll.to_h,
    nicerank: @nicerank.to_h,
    blacklist: @blacklist.to_h,
    nowplaying: @nowplaying
  }
end

#to_tableObject



258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/ayadn/preferences_object.rb', line 258

def to_table
  table = Terminal::Table.new do |t|
    if @formats.table.borders
      t.style = { :width => @formats.table.width, border_x: '', border_i: '+', border_y: '|' }
    else
      t.style = { :width => @formats.table.width, border_x: ' ', border_i: ' ', border_y: ' ' }
    end
    t.title = "Current Ayadn settings".color(:cyan)
    t.headings = [ "Category".color(:red), "Parameter".color(:red), "Value(s)".color(:red) ]
    self.to_h.each_with_index do |(k, v), index|
      v.each do |x,y|
        t << :separator if index >= 1 && !@timeline.compact
        unless y.is_a?(Hash)
          t << [ k.to_s.color(:cyan), x.to_s.color(:yellow), y.to_s.color(:green) ]
        else
          y.each do |c|
            yk = c[0]
            tempv = c[1].to_s
            if tempv.size > 10
              yv = "#{tempv[0..7]}..."
            else
              yv = tempv
            end
            t << [ k.to_s.color(:cyan), x.to_s.color(:yellow), "#{yk} = #{yv}".color(:green) ]
          end
        end
      end
    end
  end
  table
end