def apply_attributes(attributed_string, start, length, styles)
      return unless attributed_string && start && length && styles # sanity
      return unless start >= 0 && length > 0 && styles.length > 0  # minimums
      return unless start + length <= attributed_string.length     # maximums

      range = [start, length]

      ATTRIBUTES.each_pair do |method_name, attribute_name|
        value = send method_name, styles
        attributed_string.addAttribute(attribute_name, value: value, range: range) if value
      end
    end
def apply_attributes(attributed_string, start, length, styles)
      return unless attributed_string && start && length && styles # sanity
      return unless start >= 0 && length > 0 && styles.length > 0  # minimums
      return unless start + length <= attributed_string.length     # maximums

      range = [start, length]

      ATTRIBUTES.each_pair do |method_name, attribute_name|
        value = send method_name, styles
        attributed_string.addAttribute(attribute_name, value: value, range: range) if value
      end
    end
applies styles in a range to the attributed string