class Slideshow::Headers

Public Class Methods

new( config ) click to toggle source
# File lib/slideshow/headers.rb, line 7
def initialize( config )
  @hash   = {}
  @config = config
end

Public Instance Methods

[]( key ) click to toggle source
# File lib/slideshow/headers.rb, line 41
def []( key )
  value = get( key )
   
  if value.nil?
    puts "** Warning: header '#{key}' undefined"
    value = "- #{key} not found -"
  end
  value
end
code_engine() click to toggle source
# File lib/slideshow/headers.rb, line 51
def code_engine
  get( 'code-engine' )
end
code_txmt() click to toggle source
# File lib/slideshow/headers.rb, line 55
def code_txmt
  get( 'code-txmt' )
end
get( key, default=nil ) click to toggle source

todo: rename get to fetch??

# File lib/slideshow/headers.rb, line 61
def get( key, default=nil )
  key = normalize_key(key)
  value = @hash.fetch( key, nil )
  value = @config.header( key ) if value.nil?   # try lookup in config properties next
  if value.nil?
    default
  else
    value
  end
end
get_boolean( key, default ) click to toggle source
# File lib/slideshow/headers.rb, line 72
def get_boolean( key, default )
  value = get( key, default )
  if value.nil?
    default
  else
    (value == true || value =~ /t|true|yes|on/i) ? true : false
  end
end
gradient=( line ) click to toggle source
# File lib/slideshow/headers.rb, line 24
def gradient=( line )
  # split into theme (first value) and colors (everything else)
  #  e.g.  diagonal red black
  
  # todo/check: translate value w/ v.tr( '-', '_' ) ??
  
  values = line.split( ' ' )
    
  put( 'gradient-theme', values.first )                 if values.size > 0
  put( 'gradient-colors', values[ 1..-1].join( ' ' ) )  if values.size > 1
end
has_gradient?() click to toggle source
# File lib/slideshow/headers.rb, line 36
def has_gradient?
  # has user defined gradient (using headers)?  (default values do NOT count)
  @hash.has_key?( :gradient_theme ) || @hash.has_key?( :gradient_colors )
end
put( key, value ) click to toggle source

todo: rename put to store like std hash method

# File lib/slideshow/headers.rb, line 13
def put( key, value )
  key = normalize_key( key )
  setter = "#{key}=".to_sym

  if respond_to?( setter )
    send( setter, value )
  else
    @hash[ key ] = value
  end
end

Private Instance Methods

normalize_key( key ) click to toggle source
# File lib/slideshow/headers.rb, line 83
def normalize_key( key )
  key.to_s.downcase.tr('-', '_').to_sym
end