Method: Frameit::ConfigParser#validate_key

Defined in:
frameit/lib/frameit/config_parser.rb

#validate_key(key, value) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'frameit/lib/frameit/config_parser.rb', line 77

def validate_key(key, value)
  case key
  when 'font'
    UI.user_error!("Could not find font at path '#{File.expand_path(value)}'") unless File.exist?(value)
  when 'fonts'
    check_fonts(value)
  when 'background'
    UI.user_error!("Could not find background image at path '#{File.expand_path(value)}'") unless File.exist?(value)
  when 'color'
    UI.user_error!("Invalid color '#{value}'. Must be valid Hex #123123") unless value.include?("#")
  when 'padding'
    unless integer_or_percentage(value) || value.split('x').length == 2
      UI.user_error!("padding must be an integer, or pair of integers of format 'AxB', or a percentage of screen size")
    end
  when 'title_min_height'
    unless integer_or_percentage(value)
      UI.user_error!("padding must be an integer, or a percentage of screen size")
    end
  when 'show_complete_frame', 'title_below_image'
    UI.user_error!("'#{key}' must be a Boolean") unless [true, false].include?(value)
  when 'font_scale_factor'
    UI.user_error!("font_scale_factor must be numeric") unless value.kind_of?(Numeric)
  when 'frame'
    UI.user_error!("Invalid frame color '#{value}'. Frame color must be one of " + Color.all_colors.join(', ')) unless ConfigParser.supported_color?(value)
  when 'use_platform'
    UI.user_error!("Invalid platform type '#{value}'. Available values are " + Platform.all_platforms.join(', ') + ".") unless ConfigParser.supported_platform?(value)
  when 'force_device_type'
    UI.user_error!("Invalid device type '#{value}'. Available values: " + Devices.all_device_names_without_apple.join(', ')) unless ConfigParser.supported_device?(value)
  end
end